elsemTim

navigation_test

Feb 23rd, 2021 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.09 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   // This widget is the root of your application.
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return MaterialApp(
  12.       routes: {
  13.         SplashPage.routeName: (context) => SplashPage(),
  14.       },
  15.       title: 'Flutter Demo',
  16.       theme: ThemeData(
  17.         primarySwatch: Colors.blue,
  18.         visualDensity: VisualDensity.adaptivePlatformDensity,
  19.       ),
  20.       home: SplashPage(title: 'Flutter Demo Home Page'),
  21.     );
  22.   }
  23. }
  24.  
  25. class SplashPage extends StatelessWidget {
  26.   static const routeName = "splash";
  27.   final String title;
  28.  
  29.   SplashPage({
  30.     Key key,
  31.     this.title,
  32.   }) : super(key: key);
  33.  
  34.   @override
  35.   Widget build(BuildContext context) {
  36.     final bool isAuth = false;
  37.  
  38.     return Scaffold(
  39.       appBar: AppBar(
  40.         title: Text("Splash"),
  41.         centerTitle: true,
  42.       ),
  43.       body: Center(
  44.         child: Column(
  45.           mainAxisAlignment: MainAxisAlignment.center,
  46.           children: [
  47.             FlatButton(
  48.               color: Colors.red,
  49.               splashColor: Colors.green,
  50.               onPressed: () {
  51.                 Navigator.push(
  52.                     context, LoginPage(title: "123").createRoute(context));
  53.               },
  54.               child: Text("LoginPage"),
  55.             ),
  56.             FlatButton(
  57.               color: Colors.red,
  58.               splashColor: Colors.green,
  59.               onPressed: () {
  60.                 Navigator.push(
  61.                     context, HomePage(title: "123").createRoute(context));
  62.               },
  63.               child: Text("HomePage"),
  64.             ),
  65.           ],
  66.         ),
  67.       ),
  68.     );
  69.   }
  70. }
  71.  
  72. class LoginPage extends Page {
  73.   static const routeName = "login";
  74.  
  75.   final String title;
  76.  
  77.   LoginPage({
  78.     Key key,
  79.     this.title,
  80.   }) : super(key: key);
  81.  
  82.   @override
  83.   Route createRoute(BuildContext context) {
  84.     return MaterialPageRoute(
  85.       builder: (BuildContext context) {
  86.         return Scaffold(
  87.           appBar: AppBar(
  88.             leading: IconButton(
  89.               icon: Icon(Icons.arrow_back, color: Colors.black),
  90.               onPressed: () => Navigator.of(context).pop(),
  91.             ),
  92.             title: Text("Login"),
  93.             centerTitle: true,
  94.           ),
  95.           body: Center(
  96.             child: Column(
  97.               mainAxisAlignment: MainAxisAlignment.center,
  98.               children: [
  99.                 FlatButton(
  100.                   color: Colors.red,
  101.                   splashColor: Colors.green,
  102.                   onPressed: () {
  103.                     Navigator.push(
  104.                       context,
  105.                       RegistryPage().createRoute(context),
  106.                     );
  107.                   },
  108.                   child: Text("RegistryPage"),
  109.                 ),
  110.                 FlatButton(
  111.                   color: Colors.red,
  112.                   splashColor: Colors.green,
  113.                   onPressed: () {
  114.                     Navigator.push(
  115.                       context,
  116.                       HomePage().createRoute(context),
  117.                     );
  118.                   },
  119.                   child: Text("HomePage"),
  120.                 ),
  121.               ],
  122.             ),
  123.           ),
  124.         );
  125.       },
  126.     );
  127.   }
  128. }
  129.  
  130. class RegistryPage extends Page {
  131.   static const routeName = "registry";
  132.  
  133.   @override
  134.   Route createRoute(BuildContext context) {
  135.     return MaterialPageRoute(
  136.       builder: (BuildContext context) {
  137.         return Scaffold(
  138.           appBar: AppBar(
  139.             leading: IconButton(
  140.               icon: Icon(Icons.arrow_back, color: Colors.black),
  141.               onPressed: () => Navigator.of(context).pop(),
  142.             ),
  143.             title: Text("Registry"),
  144.             centerTitle: true,
  145.           ),
  146.           body: Center(
  147.             child: FlatButton(
  148.               color: Colors.red,
  149.               splashColor: Colors.green,
  150.               onPressed: () {
  151.                 Navigator.push(
  152.                   context,
  153.                   LoginPage().createRoute(context),
  154.                 );
  155.               },
  156.               child: Text("LoginPage"),
  157.             ),
  158.           ),
  159.         );
  160.       },
  161.     );
  162.   }
  163. }
  164.  
  165. class HomePage extends Page {
  166.   static const routeName = "home";
  167.  
  168.   final String title;
  169.  
  170.   HomePage({
  171.     Key key,
  172.     this.title,
  173.   }) : super(key: key);
  174.  
  175.   @override
  176.   Route createRoute(BuildContext context) {
  177.     return MaterialPageRoute(builder: (BuildContext context) {
  178.       return Scaffold(
  179.         appBar: AppBar(
  180.           leading: IconButton(
  181.             icon: Icon(Icons.arrow_back, color: Colors.black),
  182.             onPressed: () => Navigator.of(context).pop(),
  183.           ),
  184.           title: Text("Home"),
  185.           centerTitle: true,
  186.         ),
  187.         body: Center(
  188.           child: FlatButton(
  189.             color: Colors.red,
  190.             splashColor: Colors.green,
  191.             onPressed: () {
  192.               Navigator.pop(context);
  193.             },
  194.             child: Text("HomePage"),
  195.           ),
  196.         ),
  197.       );
  198.     });
  199.   }
  200. }
  201.  
Add Comment
Please, Sign In to add comment