Created
October 10, 2019 09:46
-
-
Save HenriBeck/193ea930478251b3205a6bde2c1ef650 to your computer and use it in GitHub Desktop.
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(MaterialApp( | |
home: MyApp(), | |
)); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
@override | |
void initState() { | |
super.initState(); | |
imageCache.maximumSizeBytes = 0; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
OutlineButton( | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => SecondPage( | |
depth: 1, | |
), | |
), | |
); | |
}, | |
child: Text('Push Second Page'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class SecondPage extends StatelessWidget { | |
SecondPage({ | |
@required this.depth, | |
}) : assert(depth != null); | |
final int depth; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Image.network('https://picsum.photos/id/$depth/200/200'), | |
OutlineButton( | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => SecondPage( | |
depth: depth + 1, | |
), | |
), | |
); | |
}, | |
child: Text('Push another Second page'), | |
), | |
OutlineButton( | |
onPressed: () { | |
Navigator.pop(context); | |
}, | |
child: Text('POP'), | |
), | |
OutlineButton( | |
onPressed: () { | |
Navigator.popUntil( | |
context, | |
(route) => route.isFirst, | |
); | |
}, | |
child: Text('Pop To Home'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment