Advertisement
elsemTim

nav_test_1_4

Feb 23rd, 2021
1,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.16 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.         ThirdPage.routeName: (context) => ThirdPage(),
  24.       },
  25.     );
  26.   }
  27. }
  28.  
  29. class SplashPage extends StatelessWidget {
  30.   static const routeName = "splash";
  31.   final String title;
  32.  
  33.   SplashPage({
  34.     Key key,
  35.     this.title,
  36.   }) : super(key: key);
  37.  
  38.   @override
  39.   Widget build(BuildContext context) {
  40.     return Scaffold(
  41.       appBar: AppBar(
  42.         title: Text("Splash"),
  43.         centerTitle: true,
  44.       ),
  45.       body: Center(
  46.         child: Column(
  47.           mainAxisAlignment: MainAxisAlignment.center,
  48.           children: [
  49.             FlatButton(
  50.               color: Colors.red,
  51.               splashColor: Colors.green,
  52.               onPressed: () {
  53.                 Navigator.pushReplacementNamed(
  54.                   context,
  55.                   LoginPage.routeName,
  56.                 );
  57.               },
  58.               child: Text("LoginPage"),
  59.             ),
  60.             FlatButton(
  61.               color: Colors.red,
  62.               splashColor: Colors.green,
  63.               onPressed: () {
  64.                 Navigator.pushReplacementNamed(
  65.                   context,
  66.                   HomePage.routeName,
  67.                 );
  68.               },
  69.               child: Text("HomePage"),
  70.             ),
  71.           ],
  72.         ),
  73.       ),
  74.     );
  75.   }
  76. }
  77.  
  78. class LoginPage extends StatelessWidget {
  79.   static const routeName = "login";
  80.  
  81.   final String title;
  82.  
  83.   LoginPage({
  84.     Key key,
  85.     this.title,
  86.   }) : super(key: key);
  87.  
  88.   @override
  89.   Widget build(BuildContext context) {
  90.     return Scaffold(
  91.       appBar: AppBar(
  92.         leading: IconButton(
  93.           icon: Icon(Icons.arrow_back, color: Colors.black),
  94.           onPressed: () => Navigator.of(context).pop(),
  95.         ),
  96.         title: Text("Login"),
  97.         centerTitle: true,
  98.       ),
  99.       body: Center(
  100.         child: Column(
  101.           mainAxisAlignment: MainAxisAlignment.center,
  102.           children: [
  103.             FlatButton(
  104.               color: Colors.red,
  105.               splashColor: Colors.green,
  106.               onPressed: () {
  107.                 Navigator.pushNamed(
  108.                   context,
  109.                   RegistryPage.routeName,
  110.                 );
  111.               },
  112.               child: Text("RegistryPage"),
  113.             ),
  114.             FlatButton(
  115.               color: Colors.red,
  116.               splashColor: Colors.green,
  117.               onPressed: () {
  118.                 Navigator.pushNamed(
  119.                   context,
  120.                   HomePage.routeName,
  121.                 );
  122.               },
  123.               child: Text("HomePage"),
  124.             ),
  125.           ],
  126.         ),
  127.       ),
  128.     );
  129.   }
  130. }
  131.  
  132. class RegistryPage extends StatelessWidget {
  133.   static const routeName = "registry";
  134.  
  135.   @override
  136.   Widget build(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.pushNamedAndRemoveUntil(
  152.               context,
  153.               LoginPage.routeName,
  154.               (Route<dynamic> route) => false,
  155.             );
  156.           },
  157.           child: Text("LoginPage"),
  158.         ),
  159.       ),
  160.     );
  161.   }
  162. }
  163.  
  164. class HomePage extends StatefulWidget {
  165.   static const routeName = "home";
  166.  
  167.   final String title;
  168.  
  169.   HomePage({
  170.     Key key,
  171.     this.title,
  172.   }) : super(key: key);
  173.  
  174.   @override
  175.   _HomePageState createState() => _HomePageState();
  176. }
  177.  
  178. class _HomePageState extends State<HomePage> {
  179.   int _index = 0;
  180.   List<Widget> _pages = [
  181.     FirstPage(),
  182.     SecondPage(),
  183.   ];
  184.  
  185.   @override
  186.   Widget build(BuildContext context) {
  187.     return Scaffold(
  188.       body: _pages.elementAt(_index),
  189.       bottomNavigationBar: BottomNavigationBar(
  190.         currentIndex: _index,
  191.         items: [
  192.           BottomNavigationBarItem(
  193.             icon: Icon(
  194.               Icons.home,
  195.             ),
  196.             label: "First",
  197.           ),
  198.           BottomNavigationBarItem(
  199.             icon: Icon(
  200.               Icons.account_circle_outlined,
  201.             ),
  202.             label: "Second",
  203.           ),
  204.         ],
  205.         onTap: (index) {
  206.           setState(() {
  207.             _index = index;
  208.           });
  209.         },
  210.  
  211.       ),
  212.     );
  213.   }
  214. }
  215.  
  216. class FirstPage extends StatelessWidget {
  217.   static const routeName = "first";
  218.  
  219.   @override
  220.   Widget build(BuildContext context) {
  221.     return Scaffold(
  222.       appBar: AppBar(
  223.         title: Text("First page"),
  224.         centerTitle: true,
  225.       ),
  226.       body: Center(
  227.         child: FlatButton(
  228.           color: Colors.red,
  229.           splashColor: Colors.green,
  230.           onPressed: () {
  231.             Navigator.pushNamedAndRemoveUntil(
  232.               context,
  233.               LoginPage.routeName,
  234.               (Route<dynamic> route) => false,
  235.             );
  236.           },
  237.           child: Text("LoginPage"),
  238.         ),
  239.       ),
  240.     );
  241.   }
  242. }
  243.  
  244. class SecondPage extends StatelessWidget {
  245.   static const routeName = "second";
  246.  
  247.   @override
  248.   Widget build(BuildContext context) {
  249.     return Scaffold(
  250.       appBar: AppBar(
  251.         title: Text("Second page"),
  252.         centerTitle: true,
  253.       ),
  254.       body: Center(
  255.         child: FlatButton(
  256.           color: Colors.red,
  257.           splashColor: Colors.green,
  258.           onPressed: () {
  259.             Navigator.pushNamed(
  260.               context,
  261.               ThirdPage.routeName,
  262.             );
  263.           },
  264.           child: Text("Third page"),
  265.         ),
  266.       ),
  267.     );
  268.   }
  269. }
  270.  
  271. class ThirdPage extends StatelessWidget {
  272.   static const routeName = "third";
  273.  
  274.   @override
  275.   Widget build(BuildContext context) {
  276.     return Scaffold(
  277.       appBar: AppBar(
  278.         leading: IconButton(
  279.           icon: Icon(Icons.arrow_back, color: Colors.black),
  280.           onPressed: () => Navigator.of(context).pop(),
  281.         ),
  282.         title: Text("Third page"),
  283.         centerTitle: true,
  284.       ),
  285.       body: Center(
  286.         child: FlatButton(
  287.           color: Colors.red,
  288.           splashColor: Colors.green,
  289.           onPressed: () {
  290.             Navigator.pushNamedAndRemoveUntil(
  291.               context,
  292.               LoginPage.routeName,
  293.               (Route<dynamic> route) => false,
  294.             );
  295.           },
  296.           child: Text("LoginPage"),
  297.         ),
  298.       ),
  299.     );
  300.   }
  301. }
  302.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement