assignment_to_function
Functions can't be assigned a value.
Description
#The analyzer produces this diagnostic when the name of a function appears on the left-hand side of an assignment expression.
Example
#The following code produces this diagnostic because the assignment to the function f
is invalid:
dart
void f() {}
void g() {
f = () {};
}
Common fixes
#If the right-hand side should be assigned to something else, such as a local variable, then change the left-hand side:
dart
void f() {}
void g() {
var x = () {};
print(x);
}
If the intent is to change the implementation of the function, then define a function-valued variable instead of a function:
dart
void Function() f = () {};
void g() {
f = () {};
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.