Examples of code that is invalid when the discarded_futures
lint is on:
Example 1
bad
TextButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const WebViewScreen(),
),
),
child: const Text('Open webview screen'),
),
good
Gotta add the async
.
TextButton(
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const WebViewScreen(),
),
),
child: const Text('Open webview screen'),
),
Example 2
This is worse than the first example.
Let's say the we have a method with the following signature in our widget: Future<Position> _determinePosition() async
.
Then this code is invalid:
FutureBuilder<Position>(
future: _determinePosition(),
builder: (context, snapshot) {
// ...
}
)
In this case, I worked around by making the method into a getter, but it wouldn't be possible if I needed to pass some arguments.
Example 3
Technically it's correct, but marking the closure as async
messes with mocktail
and tests fail.
Do we want to keep this lint, or should we release leancode_lint
v1.3.1 with this lint disabled (until it gets better?).