Advertisement
AbiMulya

Manual side menu

Feb 7th, 2023
1,404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.81 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(const MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   const MyApp({super.key});
  9.  
  10.   // This widget is the root of your application.
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       title: 'Flutter Demo',
  15.       theme: ThemeData(
  16.         // This is the theme of your application.
  17.         //
  18.         // Try running your application with "flutter run". You'll see the
  19.         // application has a blue toolbar. Then, without quitting the app, try
  20.         // changing the primarySwatch below to Colors.green and then invoke
  21.         // "hot reload" (press "r" in the console where you ran "flutter run",
  22.         // or simply save your changes to "hot reload" in a Flutter IDE).
  23.         // Notice that the counter didn't reset back to zero; the application
  24.         // is not restarted.
  25.         primarySwatch: Colors.blue,
  26.       ),
  27.       home: const MyHomePage(title: 'Flutter Demo Home Page'),
  28.     );
  29.   }
  30. }
  31.  
  32. class MyHomePage extends StatefulWidget {
  33.   const MyHomePage({super.key, required this.title});
  34.  
  35.   // This widget is the home page of your application. It is stateful, meaning
  36.   // that it has a State object (defined below) that contains fields that affect
  37.   // how it looks.
  38.  
  39.   // This class is the configuration for the state. It holds the values (in this
  40.   // case the title) provided by the parent (in this case the App widget) and
  41.   // used by the build method of the State. Fields in a Widget subclass are
  42.   // always marked "final".
  43.  
  44.   final String title;
  45.  
  46.   @override
  47.   State<MyHomePage> createState() => _MyHomePageState();
  48. }
  49.  
  50. class _MyHomePageState extends State<MyHomePage> {
  51.   int _counter = 0;
  52.   String _text = 'test 1';
  53.  
  54.   void _incrementCounter() {
  55.     setState(() {
  56.       // This call to setState tells the Flutter framework that something has
  57.       // changed in this State, which causes it to rerun the build method below
  58.       // so that the display can reflect the updated values. If we changed
  59.       // _counter without calling setState(), then the build method would not be
  60.       // called again, and so nothing would appear to happen.
  61.       _counter++;
  62.     });
  63.   }
  64.  
  65.   @override
  66.   Widget build(BuildContext context) {
  67.     // This method is rerun every time setState is called, for instance as done
  68.     // by the _incrementCounter method above.
  69.     //
  70.     // The Flutter framework has been optimized to make rerunning build methods
  71.     // fast, so that you can just rebuild anything that needs updating rather
  72.     // than having to individually change instances of widgets.
  73.     return Scaffold(
  74.         appBar: AppBar(
  75.           // Here we take the value from the MyHomePage object that was created by
  76.           // the App.build method, and use it to set our appbar title.
  77.           title: Text(widget.title),
  78.         ),
  79.         body: Material(
  80.           child: Row(
  81.             children: [
  82.               Container(
  83.                 width: 50,
  84.                 decoration: const BoxDecoration(
  85.                   color: Colors.red,
  86.                 ),
  87.                 child: Column(
  88.                   children: <Widget>[
  89.                     Container(
  90.                       height: 50,
  91.                       decoration: const BoxDecoration(
  92.                         color: Colors.blue,
  93.                       ),
  94.                       child: const Center(
  95.                         child: Text(
  96.                           'Side Menu',
  97.                           style: TextStyle(
  98.                             color: Colors.white,
  99.                             fontSize: 20,
  100.                             fontWeight: FontWeight.bold,
  101.                           ),
  102.                         ),
  103.                       ),
  104.                     ),
  105.                     ListTile(
  106.                       title: const Text('Home'),
  107.                       onTap: () {
  108.                         // navigate to home screen
  109.                         setState(() {
  110.                           _text = 'test 1';
  111.                         });
  112.                       },
  113.                     ),
  114.                     ListTile(
  115.                       title: const Text('Profile'),
  116.                       onTap: () {
  117.                         setState(() {
  118.                           _text = 'test 2';
  119.                         });
  120.                         // navigate to profile screen
  121.                       },
  122.                     ),
  123.                     Material(
  124.                       child: InkWell(
  125.                         splashColor: Colors.blue,
  126.                         hoverColor: Colors.red,
  127.                         onTap: () {
  128.                           setState(() {
  129.                             _text = 'test 5';
  130.                           });
  131.                           // navigate to settings screen
  132.                         },
  133.                         child: Container(
  134.                             color: Colors.blue, child: const Text('Inkwell')),
  135.                       ),
  136.                     ),
  137.                     ListTile(
  138.                       splashColor: Colors.blue,
  139.                       selectedColor: Colors.red,
  140.                       hoverColor: Colors.red,
  141.                       title: const Text('Settings'),
  142.                       onTap: () {
  143.                         setState(() {
  144.                           _text = 'test 3';
  145.                         });
  146.                         // navigate to settings screen
  147.                       },
  148.                     ),
  149.                   ],
  150.                 ),
  151.               ),
  152.               SizedBox(
  153.                 height: MediaQuery.of(context).size.height,
  154.                 width: MediaQuery.of(context).size.width - 50,
  155.                 child: Center(
  156.                   child: Text(_text),
  157.                 ),
  158.               )
  159.             ],
  160.           ),
  161.         ));
  162.   }
  163. }
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement