Last active
October 7, 2019 16:20
-
-
Save mikaelj/ca604bdec6fa8dbdd9d23bf7b9b74647 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
return BlocListener<MyBloc, MyState>( | |
listener: (context, state) { | |
if (state is QuestionState && state.attempts == 0) { | |
final attempts = state.attempts; | |
showDialog( | |
context: context, | |
barrierDismissible: false, | |
builder: (BuildContext context) { | |
return BlocBuilder<MyBloc, MyState>( | |
builder: (context, state) { | |
final bloc = BlocProvider.of<MyBloc>(context); | |
return WillPopScope( | |
onWillPop: () async => false, | |
child: AlertDialog( | |
title: Text( | |
"($attempts) Title"), | |
content: Text( | |
"($attempts) Message"), | |
actions: <Widget>[ | |
FlatButton( | |
child: Text("Cantel"), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
FlatButton( | |
child: Text("Retry"), | |
onPressed: () { | |
// RetryEvent will be mapped to QuestionState in MyBloc | |
bloc.dispatch(RetryEvent( | |
attempts: attempts + 1)); | |
}, | |
), | |
], | |
) | |
); | |
}, | |
); | |
} | |
); | |
} | |
}, | |
); |
Thanks! I'll give it a try. I find the showDialog <-> Flutter/Bloc interaction particularly hairy. Happy you're always so helpful. :-)
Maybe something for a recipe?
No problem! @mikaelj let me know if it addresses your question and I'm happy to add a recipe for blocs and dialogs 👍
@felangel Works great and turns out wasn't far away from what I had - I think moving things out to widgets (like you did) did the trick. Makes (seemingly) complex code more readable. Yeah, be great to have that as a recipe for others!
Then once the user has the basics (with your snippet), they can easily do more complex stuff like using a FutureBuilder for changing text/actions after a delay.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about something like: