-
-
Save Vanethos/6f563404e346f3ed2d4d038ed89b1955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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