Skip to content

Latest commit

 

History

History
39 lines (21 loc) · 1.35 KB

File metadata and controls

39 lines (21 loc) · 1.35 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.


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