invalid_modifier_on_setter
Setters can't use 'async', 'async*', or 'sync*'.
Description
#The analyzer produces this diagnostic when the body of a setter is prefixed by one of the following modifiers: async
, async*
, or sync*
. Setter bodies must be synchronous.
Example
#The following code produces this diagnostic because the body of the setter x
is marked as being async
:
dart
class C {
set x(int i) async {}
}
Common fixes
#If the setter can be synchronous, then remove the modifier:
dart
class C {
set x(int i) {}
}
If the setter can't be synchronous, then use a method to set the value instead:
dart
class C {
void x(int i) async {}
}
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.