Skip to content

Latest commit

History

History
43 lines (23 loc) 路 1.54 KB

File metadata and controls

43 lines (23 loc) 路 1.54 KB

Easily handle loading and error states

Note: This thread is outdated. Please see this article for an updated version: How to handle loading and error states with StateNotifier & AsyncValue in Flutter

Want to easily handle loading and error states in your widgets?

Here's an utility class I created with Freezed:

How does this work? 馃У


As this uses Freezed, you need to run:

flutter pub run build_runner build --delete-conflicting-outputs

Then you can use it like this inside a StateNotifier subclass that will represent your widget's state:


Finally, in the widget build method you can setup a listener that will show a SnackBar whenever an error state is observed.


All the code above works if you use Riverpod and Freezed in your app, so make sure they are installed.

I've got more tips like this coming along. So follow me for more: @biz84.


Found this useful? Show some love and share the original tweet 馃檹


Previous Next
AsyncValueWidget: a reusable Flutter widget to work with AsyncValue (using Riverpod) 6 common sources of errors in Flutter apps