prefer-async-callback
Same as prefer_async_callback in Pyramid Lint
- Group
- Style
- Path
lint/style/prefer-async-callback- Default
- Off, opt in
- Origin
- Pyramid Lint
- Domain
- flutter
- Rule
- 317 of 512
Flags the type Future<void> Function() in favor of Flutter's AsyncCallback.
Flutter's foundation library defines AsyncCallback as a typedef for exactly
Future<void> Function(), the standard signature for an asynchronous, argument-less
callback. Spelling the type out longhand is more verbose and less recognizable than
the named alias that the rest of the framework uses. The rule matches only the
zero-parameter function type returning Future<void>; any parameters or a different
return type leave it untouched.
Invalid
typedef OnDone = Future<void> Function();
class A {
final Future<void> Function() onSave;
A(this.onSave);
void register(Future<void> Function() cb) {}
}
Future<void> Function() make() => () async {};
void f() {
Future<void> Function() local = () async {};
local();
}typedef OnDone = Future<void> Function();class A { final Future<void> Function() onSave; void register(Future<void> Function() cb) {} Future<void> Function() make() => () async {};void f() { Future<void> Function() local = () async {};Valid
typedef OnValue = void Function();
typedef OnData = Future<void> Function(int value);
typedef Getter = Future<int> Function();
class A {
final void Function() onTap;
final Future<void> Function(String) onData;
A(this.onTap, this.onData);
}
Future<int> Function() make() => () async => 1;
void Function() other() => () {};
void f() {
void Function() local = () {};
local();
}Configure prefer-async-callback
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-async-callback": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-async-callback: <reason>More style rules
- prefer-bloc-event-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-bloc-extensionsbloc
Prefer context.read/watch over
package:flutter_bloc's provider lookups. - prefer-bloc-state-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-center-over-alignflutter
Prefers
Centerover anAlignwhose alignment is known to be centered. - prefer-collection-literals
prefer_collection_literalsrecommendedFlags no-argument collection constructor calls that a literal would express.
- prefer-commenting-analyzer-ignores
Require explanations for analyzer
ignore:andignore_for_file:comments. - prefer-const-constructors
prefer_const_constructorsPrefers
constwhen invoking aconstconstructor with constant arguments. - prefer-const-constructors-in-immutables
prefer_const_constructors_in_immutablesflutterPrefers
constconstructors in immutable classes and extension types.