Skip to content

Instantly share code, notes, and snippets.

@HenriBeck
Created October 10, 2019 09:46
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 HenriBeck/193ea930478251b3205a6bde2c1ef650 to your computer and use it in GitHub Desktop.
Save HenriBeck/193ea930478251b3205a6bde2c1ef650 to your computer and use it in GitHub Desktop.
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