Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: Page(),
- );
- }
- }
- class SlideTopRoute extends PageRouteBuilder {
- final Widget widget;
- SlideTopRoute({this.widget})
- : super(pageBuilder: (BuildContext context, Animation<double> animation,
- Animation<double> secondaryAnimation) {
- return widget;
- }, transitionsBuilder: (BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child) {
- return SlideTransition(
- position: Tween<Offset>(
- begin: const Offset(0.0, 1.0),
- end: Offset.zero,
- ).animate(animation),
- child: child,
- );
- });
- }
- class SlideBotomRoute extends PageRouteBuilder {
- final Widget enterPage;
- final Widget exitPage;
- SlideBotomRoute({this.exitPage, this.enterPage})
- : super(
- pageBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- ) =>
- enterPage,
- transitionsBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child,
- ) =>
- Stack(
- children: <Widget>[
- SlideTransition(
- position: Tween<Offset>(
- begin: Offset.zero,
- end: Offset.zero,
- ).animate(animation),
- child: enterPage,
- ),
- SlideTransition(
- position: Tween<Offset>(
- begin: Offset.zero,
- end: const Offset(0.0, 1.0),
- ).animate(animation),
- child: exitPage,
- ),
- ],
- ),
- );
- }
- class Page extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Center(
- child: RaisedButton(
- onPressed: () {
- Navigator.push(context, SlideTopRoute(widget: ModalPage()));
- },
- child: Text('Launch Modal'),
- ),
- ),
- );
- }
- }
- class ModalPage extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Modal Page'),
- ),
- body: Center(
- child: RaisedButton(
- onPressed: () {
- final Route<SecondaryPage> secondaryRoute = MaterialPageRoute(
- settings: RouteSettings(name: 'Secondary'),
- builder: (BuildContext context) => SecondaryPage(),
- );
- Navigator.push(context, secondaryRoute);
- },
- child: Text('Launch Secondary Page'),
- ),
- ),
- );
- }
- }
- class SecondaryPage extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(title: Text('Secondary Page')),
- body: Center(
- child: RaisedButton(
- onPressed: () {
- Navigator.pushAndRemoveUntil(
- context,
- SlideBotomRoute(exitPage: this, enterPage: Page()),
- ModalRoute.withName('/'));
- },
- child: Text('Clear All'),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement