Either declare the function as static in your class or move it outside the class altogether. If the field isn’t final (which for best practice, it should be, unless the field has to mutate), you can initialize it using a regular non-static method in the constructor body .
Read moreHow do you define a function in darts?
Defining the function in Dart: Dart provides us with the facility of using functions in its program. Syntax: return_type function_name ( parameters ) { // Body of function return value ; } In the above syntax: function_name defines the name of the function.
Read moreHow do you pass a function in Flutter?
Dart: How to pass a function into a function (using a Function as a method parameter)
Read more