Created
March 26, 2020 00:31
-
-
Save imaNNeo/17b7c2009b3a258873685963639965de to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Page1(), | |
); | |
} | |
} | |
class Page1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Page1'), | |
), | |
body: Builder( | |
builder: (context) { | |
return Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
RaisedButton( | |
onPressed: () { | |
Scaffold.of(context).showSnackBar(SnackBar(content: Text('SnackBar'))); | |
}, | |
child: Text('1. Click to show SnackBar')), | |
RaisedButton( | |
onPressed: () { | |
Navigator.of(context) | |
.push(new MaterialPageRoute(builder: (context) => Page2())); | |
}, | |
child: Text('2. Then click to navigate')), | |
], | |
)); | |
}, | |
), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Page2'), | |
), | |
body: Center( | |
child: Text( | |
'after 5 seconds get back to previous page', | |
style: TextStyle( | |
fontSize: 18, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment