use-ref-read-synchronously
Warns when ref.read
is called past an await point (also known as asynchronous gap).
Example
❌ Bad:
class HomeConsumerState extends ConsumerState<HomeConsumerStatefulWidget> {
Widget build(context) {
return FooWidget(
onChange: (value) async {
ref.read<WithAsync>();
await fetch();
ref.read<WithAsync>(); // LINT
},
);
}
}
✅ Good:
class HomeConsumerState extends ConsumerState<HomeConsumerStatefulWidget> {
Widget build(context) {
return FooWidget(
onChange: (value) async {
ref.read<WithAsync>();
await fetch();
if (mounted) {
ref.read<WithAsync>();
}
},
);
}
}