Create by https://gist.github.com/CaiJingLong/a299d15b92edc2d09a8a06cf6dd5a1b0
Created
February 26, 2020 09:59
-
-
Save CaiJingLong/ff332447d9aded662f8afcf7d5cf2fe3 to your computer and use it in GitHub Desktop.
pop to root
This file contains hidden or 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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
// This is the theme of your application. | |
// | |
// Try running your application with "flutter run". You'll see the | |
// application has a blue toolbar. Then, without quitting the app, try | |
// changing the primarySwatch below to Colors.green and then invoke | |
// "hot reload" (press "r" in the console where you ran "flutter run", | |
// or simply save your changes to "hot reload" in a Flutter IDE). | |
// Notice that the counter didn't reset back to zero; the application | |
// is not restarted. | |
primarySwatch: Colors.blue, | |
), | |
home: HomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class HomePage extends StatelessWidget { | |
final String title; | |
final int level; | |
const HomePage({Key key, this.title, this.level = 0}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("$title $level"), | |
), | |
body: Column( | |
children: <Widget>[ | |
RaisedButton( | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (_) { | |
return HomePage( | |
title: title, | |
level: level + 1, | |
); | |
}, | |
), | |
); | |
}, | |
child: Text("next"), | |
), | |
RaisedButton( | |
onPressed: () { | |
for (var i = 0; i < level; i++) { | |
Navigator.pop(context); | |
} | |
}, | |
child: Text("to root"), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment