Skip to content

Instantly share code, notes, and snippets.

@Vanethos
Created May 6, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vanethos/6f563404e346f3ed2d4d038ed89b1955 to your computer and use it in GitHub Desktop.
Save Vanethos/6f563404e346f3ed2d4d038ed89b1955 to your computer and use it in GitHub Desktop.
mixin ErrorHandlingMixin<Page extends BasePage> on BaseState<Page> {
@override
void initState() {
super.initState();
widget.bloc.errorStream
// this will preven multiple messages from showing up in a short interval of time
.transform(new ThrottleStreamTransformer((_) => TimerStream(true, const Duration(seconds: 2))))
.listen((error) => showErrorSnackbar(error, scaffoldKey.currentState));
}
void showErrorSnackbar(String event, ScaffoldState context) {
if (event != null) {
context.showSnackBar(new SnackBar(
content: new Text(event),
));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment