Created
January 25, 2020 18:35
-
-
Save Christopher2K/53302e252338c01cd697ceeeb844db14 to your computer and use it in GitHub Desktop.
[Clear the stack and push a new screen] How to reset the stack and push a new screen a flutter to avoid the back behaviour #flutter #dart
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
class MyWidget extends StatelessWidget { | |
void _clearStackAndPush (BuildContext context) { | |
Navigator.of(context).pushNamedAndRemoveUntil( | |
'/screen-name', | |
() => false, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: FlatButton( | |
child: Text('Click me'), | |
onPressed: () => this._clearStackAndPush(context), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment