Advertisement
elsemTim

nav_test_1_3

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