Advertisement
elsemTim

nav_test_1_1

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