Skip to content

Instantly share code, notes, and snippets.

@Christopher2K
Created January 25, 2020 18:35
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 Christopher2K/53302e252338c01cd697ceeeb844db14 to your computer and use it in GitHub Desktop.
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
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