riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Create lint rule for using `ref.read` after an async operation

Open JulianBissekkou opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. The flutter framework gives a warning when using the buildcontext async. use_build_context_synchronously. It would be nice to have something similar if we are using ref.read in a ConsumerStatefulWidget.

class MyScreen extends ConsumerStatefulWidget {

  Future<void> onSomeButtonTap() async {
    await ref.read(myStateNotifierProvider).loadSomeData();
    if(!mounted) return; // would be nice to have a warning if this line is not present.
    await ref.read(myOtherStateNotifierProvider).loadSomeMoreData();
    if(!mounted) return;
  }
}

Describe the solution you'd like I think its not as easy to implement as use_build_context_synchronously but it would be nice to have something like use_widget_ref_synchronously.

Describe alternatives you've considered We can always run ProviderScope.of(context).read(provider) then we get the warning, but that's too much code.

JulianBissekkou avatar Jun 23 '23 11:06 JulianBissekkou