Advertisement
Guest User

Modale

a guest
Apr 4th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.68 KB | None | 0 0
  1.  
  2. void main() {
  3.   runApp(MyApp());
  4. }
  5.  
  6. class MyApp extends StatelessWidget {
  7.   // This widget is the root of your application.
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       debugShowCheckedModeBanner: false,
  12.       title: 'Flutter Demo',
  13.       theme: ThemeData(
  14.         primarySwatch: Colors.blue,
  15.       ),
  16.       home: Page(),
  17.     );
  18.   }
  19. }
  20.  
  21. class SlideTopRoute extends PageRouteBuilder {
  22.   final Widget widget;
  23.   SlideTopRoute({this.widget})
  24.       : super(pageBuilder: (BuildContext context, Animation<double> animation,
  25.             Animation<double> secondaryAnimation) {
  26.           return widget;
  27.         }, transitionsBuilder: (BuildContext context,
  28.             Animation<double> animation,
  29.             Animation<double> secondaryAnimation,
  30.             Widget child) {
  31.           return SlideTransition(
  32.             position: Tween<Offset>(
  33.               begin: const Offset(0.0, 1.0),
  34.               end: Offset.zero,
  35.             ).animate(animation),
  36.             child: child,
  37.           );
  38.         });
  39. }
  40.  
  41. class SlideBotomRoute extends PageRouteBuilder {
  42.   final Widget enterPage;
  43.   final Widget exitPage;
  44.   SlideBotomRoute({this.exitPage, this.enterPage})
  45.       : super(
  46.           pageBuilder: (
  47.             BuildContext context,
  48.             Animation<double> animation,
  49.             Animation<double> secondaryAnimation,
  50.           ) =>
  51.               enterPage,
  52.           transitionsBuilder: (
  53.             BuildContext context,
  54.             Animation<double> animation,
  55.             Animation<double> secondaryAnimation,
  56.             Widget child,
  57.           ) =>
  58.               Stack(
  59.             children: <Widget>[
  60.               SlideTransition(
  61.                 position: Tween<Offset>(
  62.                   begin: Offset.zero,
  63.                   end: Offset.zero,
  64.                 ).animate(animation),
  65.                 child: enterPage,
  66.               ),
  67.               SlideTransition(
  68.                 position: Tween<Offset>(
  69.                   begin: Offset.zero,
  70.                   end: const Offset(0.0, 1.0),
  71.                 ).animate(animation),
  72.                 child: exitPage,
  73.               ),
  74.             ],
  75.           ),
  76.         );
  77. }
  78.  
  79. class Page extends StatelessWidget {
  80.   @override
  81.   Widget build(BuildContext context) {
  82.     return Scaffold(
  83.       body: Center(
  84.         child: RaisedButton(
  85.           onPressed: () {
  86.             Navigator.push(context, SlideTopRoute(widget: ModalPage()));
  87.           },
  88.           child: Text('Launch Modal'),
  89.         ),
  90.       ),
  91.     );
  92.   }
  93. }
  94.  
  95. class ModalPage extends StatelessWidget {
  96.   @override
  97.   Widget build(BuildContext context) {
  98.     return Scaffold(
  99.       appBar: AppBar(
  100.         title: Text('Modal Page'),
  101.       ),
  102.       body: Center(
  103.         child: RaisedButton(
  104.           onPressed: () {
  105.             final Route<SecondaryPage> secondaryRoute = MaterialPageRoute(
  106.               settings: RouteSettings(name: 'Secondary'),
  107.               builder: (BuildContext context) => SecondaryPage(),
  108.             );
  109.             Navigator.push(context, secondaryRoute);
  110.           },
  111.           child: Text('Launch Secondary Page'),
  112.         ),
  113.       ),
  114.     );
  115.   }
  116. }
  117.  
  118. class SecondaryPage extends StatelessWidget {
  119.   @override
  120.   Widget build(BuildContext context) {
  121.     return Scaffold(
  122.       appBar: AppBar(title: Text('Secondary Page')),
  123.       body: Center(
  124.         child: RaisedButton(
  125.           onPressed: () {
  126.             Navigator.pushAndRemoveUntil(
  127.                 context,
  128.                 SlideBotomRoute(exitPage: this, enterPage: Page()),
  129.                 ModalRoute.withName('/'));
  130.           },
  131.           child: Text('Clear All'),
  132.         ),
  133.       ),
  134.     );
  135.   }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement