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
flutter

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

example.dartdart
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();
}
Use `AsyncCallback` instead of `Future<void> Function()`.
1typedef OnDone = Future<void> Function();
Use `AsyncCallback` instead of `Future<void> Function()`.
3class A {
4 final Future<void> Function() onSave;
Use `AsyncCallback` instead of `Future<void> Function()`.
7
8 void register(Future<void> Function() cb) {}
Use `AsyncCallback` instead of `Future<void> Function()`.
10
11Future<void> Function() make() => () async {};
Use `AsyncCallback` instead of `Future<void> Function()`.
13void f() {
14 Future<void> Function() local = () async {};

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-async-callback": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/prefer-async-callback: <reason>