jpfassis

Page Web Flutter

Feb 7th, 2022 (edited)
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 13.46 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3.  
  4. void main() {
  5.   runApp(
  6.     const MaterialApp(
  7.       home: MyWidget(),
  8.     ),
  9.   );
  10. }
  11.  
  12. class CustomListTile extends StatelessWidget {
  13.   @override
  14.   Widget build(BuildContext context) {
  15.     return InkWell(
  16.       child: Row(
  17.         children: [
  18.           Icon(Icons.person),
  19.           Text('Profile'),
  20.           Icon(Icons.arrow_right)
  21.         ],
  22.       ),
  23.     );
  24.   }
  25. }
  26.  
  27. class MyWidget extends StatelessWidget {
  28.   const MyWidget({Key? key}) : super(key: key);
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return RedContainer(
  32.       builder: (_) => Container(
  33.           color: Colors.green,
  34.           child: Column(children: [
  35.             Text('${MediaQuery.of(context).size}',
  36.                 style: const TextStyle(fontSize: 40)),
  37.           ])),
  38.     );
  39.   }
  40. }
  41.  
  42. class RedContainer extends StatelessWidget {
  43.   const RedContainer({Key? key, required this.builder})
  44.       : assert(builder != null),
  45.         super(key: key);
  46.   final WidgetBuilder builder;
  47.   @override
  48.   Widget build(BuildContext context) {
  49.     final mq = MediaQuery.of(context);
  50.     final modalWidth = calculateModalWidth(mq.size);
  51.     final isScreenLarge = mq.size.width > 850;
  52.  
  53.     return Scaffold(
  54.       body: Row(
  55.         children: [
  56.           if (isScreenLarge)
  57.             Container(
  58.                 height: double.infinity,
  59.                 width: modalWidth,
  60.                 color: Colors.indigo[600],
  61.                 child: generateMenu(context)),
  62.           generateMainContent(context, mq.size, isScreenLarge),
  63.         ],
  64.       ),
  65.     );
  66.   }
  67.  
  68.   double calculateModalWidth(Size screenSize) {
  69.     const minWidth = 200.0;
  70.     const maxWidth = 250.0;
  71.  
  72.     final proposedWidth = screenSize.width / 4;
  73.  
  74.     if (proposedWidth > maxWidth) {
  75.       return maxWidth;
  76.     } else if (proposedWidth < minWidth) {
  77.       return minWidth;
  78.     }
  79.     return proposedWidth;
  80.   }
  81.  
  82.   Widget generatePopupMenu(context) => Container(
  83.         child: Align(
  84.           alignment: Alignment.centerRight,
  85.           child: PopupMenuButton<int>(
  86.             itemBuilder: (context) => const [
  87.               PopupMenuItem(
  88.                 value: 1,
  89.                 child: Text(
  90.                   "Flutter Open",
  91.                   style: TextStyle(
  92.                       color: Colors.black, fontWeight: FontWeight.w700),
  93.                 ),
  94.               ),
  95.               PopupMenuItem(
  96.                 value: 2,
  97.                 child: Text(
  98.                   "Flutter Tutorial",
  99.                   style: TextStyle(
  100.                       color: Colors.black, fontWeight: FontWeight.w700),
  101.                 ),
  102.               ),
  103.             ],
  104.             icon: const Icon(Icons.more_vert, color: Colors.white),
  105.             offset: const Offset(0, 50),
  106.           ),
  107.         ),
  108.       );
  109.  
  110.   Widget generateAvatar(context) {
  111.     return Column(
  112.       children: <Widget>[
  113.         UserAccountsDrawerHeader(
  114.             accountName: Text('Usuário Teste 001',
  115.                 style: TextStyle(color: Colors.white70, fontSize: 18)),
  116.             accountEmail: Text('*********@gmail.com'),
  117.             currentAccountPicture: GestureDetector(
  118.                 child: CircleAvatar(
  119.                     backgroundColor: Colors.indigo[600],
  120.                     child:
  121.                         Icon(Icons.person, size: 38.0, color: Colors.white))),
  122.             decoration: BoxDecoration(color: Colors.indigo[200])),
  123.         // Divider(color: Colors.red[100]),
  124.       ],
  125.     );
  126.   }
  127.  
  128.   Widget generateMenu(context) {
  129.     return Padding(
  130.         padding: const EdgeInsets.only(left: 15.0, right: 15.0),
  131.         child: Align(
  132.           alignment: Alignment.centerLeft,
  133.           child: Column(
  134.             mainAxisSize: MainAxisSize.min,
  135.             mainAxisAlignment: MainAxisAlignment.spaceAround,
  136.             crossAxisAlignment: CrossAxisAlignment.start,
  137.             children: <Widget>[
  138.               Expanded(
  139.                 child: ListView(
  140.                   children: <Widget>[
  141.                     SizedBox(height: 10),
  142.                     generateAvatar(context),
  143.                     TextButton(
  144.                         onPressed: () {},
  145.                         child: Row(
  146.                           children: const <Widget>[
  147.                             Icon(Icons.dashboard,
  148.                                 size: 23.0, color: Colors.white),
  149.                             SizedBox(width: 10),
  150.                             Text("Dashboard",
  151.                                 style: TextStyle(
  152.                                     color: Colors.white, fontSize: 16))
  153.                           ],
  154.                         )),
  155.                     const SizedBox(height: 10),
  156.                     TextButton(
  157.                         onPressed: () {},
  158.                         child: Row(
  159.                           children: const <Widget>[
  160.                             Icon(Icons.people, size: 23.0, color: Colors.white),
  161.                             SizedBox(width: 10),
  162.                             Text("Clientes",
  163.                                 style: TextStyle(
  164.                                     color: Colors.white, fontSize: 16))
  165.                           ],
  166.                         )),
  167.                     SizedBox(height: 10),
  168.                     TextButton(
  169.                         onPressed: () {},
  170.                         child: Row(
  171.                           children: const <Widget>[
  172.                             Icon(Icons.contact_mail_outlined,
  173.                                 size: 23.0, color: Colors.white),
  174.                             SizedBox(width: 10),
  175.                             Text("Fornecedores",
  176.                                 style: TextStyle(
  177.                                     color: Colors.white, fontSize: 16))
  178.                           ],
  179.                         )),
  180.                     SizedBox(height: 10),
  181.                     TextButton(
  182.                         onPressed: () {},
  183.                         child: Row(
  184.                           children: const <Widget>[
  185.                             Icon(Icons.local_bar,
  186.                                 size: 23.0, color: Colors.white),
  187.                             SizedBox(width: 10),
  188.                             Text("Produtos",
  189.                                 style: TextStyle(
  190.                                     color: Colors.white, fontSize: 16))
  191.                           ],
  192.                         )),
  193.                     SizedBox(height: 10),
  194.                     TextButton(
  195.                         onPressed: () {},
  196.                         child: Row(
  197.                           children: const <Widget>[
  198.                             Icon(Icons.account_circle_outlined,
  199.                                 size: 23.0, color: Colors.white),
  200.                             SizedBox(width: 10),
  201.                             Text("Usuários",
  202.                                 style: TextStyle(
  203.                                     color: Colors.white, fontSize: 16))
  204.                           ],
  205.                         )),
  206.                     SizedBox(height: 10),
  207.                     TextButton(
  208.                         onPressed: () {},
  209.                         child: Row(
  210.                           children: const <Widget>[
  211.                             Icon(Icons.summarize_outlined,
  212.                                 size: 23.0, color: Colors.white),
  213.                             SizedBox(width: 10),
  214.                             Text("Orçamentos",
  215.                                 style: TextStyle(
  216.                                     color: Colors.white, fontSize: 16))
  217.                           ],
  218.                         )),
  219.                     SizedBox(height: 10),
  220.                     TextButton(
  221.                         onPressed: () {},
  222.                         child: Row(
  223.                           children: const <Widget>[
  224.                             Icon(Icons.dvr, size: 23.0, color: Colors.white),
  225.                             SizedBox(width: 10),
  226.                             Text("Pedidos",
  227.                                 style: TextStyle(
  228.                                     color: Colors.white, fontSize: 16))
  229.                           ],
  230.                         )),
  231.                     SizedBox(height: 10),
  232.                     TextButton(
  233.                         onPressed: () {},
  234.                         child: Row(
  235.                           children: const <Widget>[
  236.                             Icon(Icons.receipt_long,
  237.                                 size: 23.0, color: Colors.white),
  238.                             SizedBox(width: 10),
  239.                             Text("Notas Fiscais",
  240.                                 style: TextStyle(
  241.                                     color: Colors.white, fontSize: 16))
  242.                           ],
  243.                         )),
  244.                     SizedBox(height: 10),
  245.                     TextButton(
  246.                         onPressed: () {},
  247.                         child: Row(
  248.                           children: const <Widget>[
  249.                             Icon(Icons.local_atm,
  250.                                 size: 23.0, color: Colors.white),
  251.                             SizedBox(width: 10),
  252.                             Text("Contas a Pagar",
  253.                                 style: TextStyle(
  254.                                     color: Colors.white, fontSize: 16))
  255.                           ],
  256.                         )),
  257.                     SizedBox(height: 10),
  258.                     TextButton(
  259.                         onPressed: () {},
  260.                         child: Row(
  261.                           children: const <Widget>[
  262.                             Icon(Icons.paid_outlined,
  263.                                 size: 23.0, color: Colors.white),
  264.                             SizedBox(width: 10),
  265.                             Text("Contas a Receber",
  266.                                 style: TextStyle(
  267.                                     color: Colors.white, fontSize: 16))
  268.                           ],
  269.                         )),
  270.                     SizedBox(height: 10),
  271.                     TextButton(
  272.                         onPressed: () {},
  273.                         child: Row(
  274.                           children: const <Widget>[
  275.                             Icon(Icons.settings,
  276.                                 size: 23.0, color: Colors.white),
  277.                             SizedBox(width: 10),
  278.                             Text("Configurações",
  279.                                 style: TextStyle(
  280.                                     color: Colors.white, fontSize: 16))
  281.                           ],
  282.                         )),
  283.                     SizedBox(height: 10),
  284.                     TextButton(
  285.                         onPressed: () {},
  286.                         child: Row(
  287.                           children: const <Widget>[
  288.                             Icon(Icons.meeting_room,
  289.                                 size: 23.0, color: Colors.white),
  290.                             SizedBox(width: 10),
  291.                             Text("Sair",
  292.                                 style: TextStyle(
  293.                                     color: Colors.white, fontSize: 16))
  294.                           ],
  295.                         )),
  296.                   ],
  297.                 ),
  298.               ),
  299.             ],
  300.           ),
  301.         ));
  302.   }
  303.  
  304.   Widget generateMainContent(
  305.       BuildContext context, Size screenSize, bool isScreenLarge) {
  306.     assert(screenSize != null);
  307.     final modalWidth = isScreenLarge ? calculateModalWidth(screenSize) : 0;
  308.  
  309.     return Container(
  310.       width: screenSize.width - modalWidth,
  311.       child: Column(children: [
  312.         Container(
  313.           height: 70,
  314.           color: const Color(0xFF272D34), //Colors.red
  315.           child: Row(
  316.             children: [
  317.               generatePopupMenu(context),
  318.               SimpleClock(),
  319.               Text(" - Tribo Flutter ERP ",
  320.                   style: const TextStyle(color: Colors.white70, fontSize: 24)),
  321.               SizedBox(width: 10),
  322.               if (!isScreenLarge)
  323.                 Material(
  324.                   color: Colors.transparent,
  325.                   child: Ink(
  326.                     decoration: const ShapeDecoration(
  327.                       color: Colors.blue,
  328.                       shape: CircleBorder(),
  329.                     ),
  330.                     child: IconButton(
  331.                       icon: const Icon(Icons.menu),
  332.                       color: Colors.white,
  333.                       tooltip: 'Menu',
  334.                       onPressed: () {},
  335.                     ),
  336.                   ),
  337.                 ),
  338.             ],
  339.           ),
  340.         ),
  341.         Expanded(
  342.           child: builder(context),
  343.         ),
  344.       ]),
  345.     );
  346.   }
  347. }
  348.  
  349. class SimpleClock extends StatefulWidget {
  350.   @override
  351.   _SimpleClockState createState() => _SimpleClockState();
  352. }
  353.  
  354. class _SimpleClockState extends State<SimpleClock> {
  355.   late String _timeString;
  356.   @override
  357.   void initState() {
  358.     _timeString =
  359.         "${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}";
  360.     Timer.periodic(Duration(seconds: 1), (Timer t) => _getCurrentTime());
  361.     super.initState();
  362.   }
  363.  
  364.   @override
  365.   Widget build(BuildContext context) {
  366.     return Container(
  367.       child: Text(
  368.         _timeString,
  369.         style: TextStyle(color: Colors.white70, fontSize: 24),
  370.       ),
  371.     );
  372.   }
  373.  
  374.   void _getCurrentTime() {
  375.     setState(() {
  376.       _timeString =
  377.           "${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}";
  378.     });
  379.   }
  380. }
  381.  
Add Comment
Please, Sign In to add comment