Want to show a SnackBar from async executions when no context is available? As a direct child of your StoreProvider, create your own InheritedWidget that holds the stream of errors, named SyncErrorProvider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class SyncErrorProvider extends InheritedWidget { const SyncErrorProvider({Key key, this.errors, @required Widget child}) : assert(child != null), super(key: key, child: child); final Stream<Object> errors; static SyncErrorProvider of(BuildContext context) { return context.inheritFromWidgetOfExactType(SyncErrorProvider) as SyncErrorProvider; } @override bool updateShouldNotify(SyncErrorProvider old) => errors != old.errors; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.