Advertisement
Zuhairy_Harry

screen.dart

Jun 12th, 2025
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 15.63 KB | None | 0 0
  1. import 'package:einventorycomputer/modules/home/screen/location/location.dart';
  2. import 'package:einventorycomputer/services/auth.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:firebase_auth/firebase_auth.dart';
  5. import 'package:cloud_firestore/cloud_firestore.dart';
  6. import 'package:einventorycomputer/modules/home/screen/home.dart';
  7. import 'package:einventorycomputer/modules/home/screen/devices/inventory.dart';
  8. import 'package:einventorycomputer/modules/home/screen/settings/settings.dart';
  9. import 'package:einventorycomputer/modules/home/screen/user/account.dart';
  10. import 'package:einventorycomputer/modules/home/screen/devices/add_device.dart';
  11.  
  12. class ScreenPage extends StatefulWidget {
  13.   @override
  14.   _ScreenPageState createState() => _ScreenPageState();
  15. }
  16.  
  17. class _ScreenPageState extends State<ScreenPage> with TickerProviderStateMixin {
  18.   final AuthService _auth = AuthService();
  19.   int _selectedIndex = 0;
  20.   String? _username;
  21.   late AnimationController _drawerAnimationController;
  22.  
  23.   final List<String> _titles = [
  24.     "Home",
  25.     "Inventory",
  26.     "Add Device",
  27.     "Settings",
  28.     "Account",
  29.     "Location",
  30.   ];
  31.  
  32.   final List<Widget> _pages = [
  33.     HomePage(),
  34.     InventoryPage(),
  35.     AddDevicePage(),
  36.     SettingsPage(),
  37.     AccountPage(),
  38.     LocationPage(),
  39.   ];
  40.  
  41.   // Define which indices are in the bottom navigation
  42.   final List<int> _bottomNavIndexes = [0, 1, 4, 5];
  43.  
  44.   @override
  45.   void initState() {
  46.     super.initState();
  47.     _loadUsername();
  48.     _drawerAnimationController = AnimationController(
  49.       duration: const Duration(milliseconds: 300),
  50.       vsync: this,
  51.     );
  52.   }
  53.  
  54.   @override
  55.   void dispose() {
  56.     _drawerAnimationController.dispose();
  57.     super.dispose();
  58.   }
  59.  
  60.   Future<void> _loadUsername() async {
  61.     final user = FirebaseAuth.instance.currentUser;
  62.     if (user != null) {
  63.       final doc = await FirebaseFirestore.instance.collection('users').doc(user.uid).get();
  64.       if (doc.exists) {
  65.         setState(() {
  66.           _username = doc.data()?['username'] ?? 'User';
  67.         });
  68.       }
  69.     }
  70.   }
  71.  
  72.   void _onSelect(int index) {
  73.     if (_selectedIndex != index) {
  74.       setState(() {
  75.         _selectedIndex = index;
  76.       });
  77.     }
  78.     Navigator.pop(context); // Close drawer
  79.   }
  80.  
  81.   @override
  82.   Widget build(BuildContext context) {
  83.     final isBottomNavPage = _bottomNavIndexes.contains(_selectedIndex);
  84.     final safeCurrentIndex = _bottomNavIndexes.indexWhere((i) => i == _selectedIndex);
  85.  
  86.     return Scaffold(
  87.       backgroundColor: const Color(0xFFF8F9FA),
  88.       appBar: AppBar(
  89.         title: Text(
  90.           _titles[_selectedIndex],
  91.           style: const TextStyle(
  92.             fontFamily: 'SansRegular',
  93.             color: Color(0xFF212529),
  94.             fontWeight: FontWeight.w600,
  95.             fontSize: 20,
  96.           ),
  97.         ),
  98.         backgroundColor: Colors.transparent,
  99.         elevation: 0,
  100.         iconTheme: const IconThemeData(color: Color(0xFF212529)),
  101.         leading: Builder(
  102.           builder: (context) => IconButton(
  103.             icon: Container(
  104.               padding: const EdgeInsets.all(8),
  105.               decoration: BoxDecoration(
  106.                 color: Colors.white,
  107.                 borderRadius: BorderRadius.circular(12),
  108.                 boxShadow: [
  109.                   BoxShadow(
  110.                     color: Colors.black.withOpacity(0.1),
  111.                     blurRadius: 8,
  112.                     offset: const Offset(0, 2),
  113.                   ),
  114.                 ],
  115.               ),
  116.               child: const Icon(
  117.                 Icons.menu_rounded,
  118.                 color: Color(0xFF212529),
  119.                 size: 20,
  120.               ),
  121.             ),
  122.             onPressed: () => Scaffold.of(context).openDrawer(),
  123.           ),
  124.         ),
  125.       ),
  126.       drawer: Drawer(
  127.         backgroundColor: Colors.white,
  128.         elevation: 0,
  129.         child: SafeArea(
  130.           child: Column(
  131.             children: [
  132.               // Header Section
  133.               Container(
  134.                 width: double.infinity,
  135.                 padding: const EdgeInsets.all(24),
  136.                 decoration: const BoxDecoration(
  137.                   color: Color(0xFF212529),
  138.                   borderRadius: BorderRadius.only(
  139.                     bottomLeft: Radius.circular(24),
  140.                     bottomRight: Radius.circular(24),
  141.                   ),
  142.                 ),
  143.                 child: Column(
  144.                   children: [
  145.                     Container(
  146.                       width: 80,
  147.                       height: 80,
  148.                       decoration: BoxDecoration(
  149.                         color: const Color(0xFFFFC727),
  150.                         borderRadius: BorderRadius.circular(20),
  151.                         boxShadow: [
  152.                           BoxShadow(
  153.                             color: const Color(0xFFFFC727).withOpacity(0.3),
  154.                             blurRadius: 12,
  155.                             offset: const Offset(0, 4),
  156.                           ),
  157.                         ],
  158.                       ),
  159.                       child: const Icon(
  160.                         Icons.person_rounded,
  161.                         size: 40,
  162.                         color: Color(0xFF212529),
  163.                       ),
  164.                     ),
  165.                     const SizedBox(height: 16),
  166.                     Text(
  167.                       _username ?? 'Loading...',
  168.                       style: const TextStyle(
  169.                         fontFamily: 'SansRegular',
  170.                         fontWeight: FontWeight.w600,
  171.                         fontSize: 18,
  172.                         color: Color(0xFFFFC727),
  173.                       ),
  174.                     ),
  175.                     const SizedBox(height: 4),
  176.                     Text(
  177.                       FirebaseAuth.instance.currentUser?.email ?? '',
  178.                       style: const TextStyle(
  179.                         fontFamily: 'SansRegular',
  180.                         fontSize: 14,
  181.                         color: Color(0xFFADB5BD),
  182.                       ),
  183.                       overflow: TextOverflow.ellipsis,
  184.                     ),
  185.                   ],
  186.                 ),
  187.               ),
  188.              
  189.               const SizedBox(height: 24),
  190.              
  191.               // Navigation Items
  192.               Expanded(
  193.                 child: Padding(
  194.                   padding: const EdgeInsets.symmetric(horizontal: 16),
  195.                   child: Column(
  196.                     children: [
  197.                       _buildDrawerItem(Icons.home_outlined, Icons.home_rounded, "Home", 0),
  198.                       _buildDrawerItem(Icons.inventory_2_outlined, Icons.inventory_2_rounded, "Inventory", 1),
  199.                       _buildDrawerItem(Icons.add_box_outlined, Icons.add_box_rounded, "Add Device", 2),
  200.                       _buildDrawerItem(Icons.settings_outlined, Icons.settings_rounded, "Settings", 3),
  201.                       _buildDrawerItem(Icons.person_outline_rounded, Icons.person_rounded, "Account", 4),
  202.                       _buildDrawerItem(Icons.location_city_outlined, Icons.location_city_rounded, "Location", 5),
  203.                     ],
  204.                   ),
  205.                 ),
  206.               ),
  207.              
  208.               // Logout Section
  209.               Padding(
  210.                 padding: const EdgeInsets.all(24),
  211.                 child: Container(
  212.                   width: double.infinity,
  213.                   decoration: BoxDecoration(
  214.                     gradient: const LinearGradient(
  215.                       colors: [Color(0xFF212529), Color(0xFF343A40)],
  216.                       begin: Alignment.topLeft,
  217.                       end: Alignment.bottomRight,
  218.                     ),
  219.                     borderRadius: BorderRadius.circular(16),
  220.                     boxShadow: [
  221.                       BoxShadow(
  222.                         color: Colors.black.withOpacity(0.1),
  223.                         blurRadius: 12,
  224.                         offset: const Offset(0, 4),
  225.                       ),
  226.                     ],
  227.                   ),
  228.                   child: Material(
  229.                     color: Colors.transparent,
  230.                     child: InkWell(
  231.                       borderRadius: BorderRadius.circular(16),
  232.                       onTap: () async {
  233.                         await _auth.signOut();
  234.                       },
  235.                       child: Padding(
  236.                         padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
  237.                         child: Row(
  238.                           mainAxisAlignment: MainAxisAlignment.center,
  239.                           children: [
  240.                             Container(
  241.                               padding: const EdgeInsets.all(8),
  242.                               decoration: BoxDecoration(
  243.                                 color: const Color(0xFFFFC727).withOpacity(0.2),
  244.                                 borderRadius: BorderRadius.circular(8),
  245.                               ),
  246.                               child: const Icon(
  247.                                 Icons.logout_rounded,
  248.                                 color: Color(0xFFFFC727),
  249.                                 size: 20,
  250.                               ),
  251.                             ),
  252.                             const SizedBox(width: 12),
  253.                             const Text(
  254.                               "Sign Out",
  255.                               style: TextStyle(
  256.                                 fontSize: 16,
  257.                                 fontWeight: FontWeight.w600,
  258.                                 color: Color(0xFFFFC727),
  259.                                 fontFamily: 'SansRegular',
  260.                               ),
  261.                             ),
  262.                           ],
  263.                         ),
  264.                       ),
  265.                     ),
  266.                   ),
  267.                 ),
  268.               ),
  269.             ],
  270.           ),
  271.         ),
  272.       ),
  273.       body: _pages[_selectedIndex],
  274.       bottomNavigationBar: isBottomNavPage
  275.           ? Container(
  276.               margin: const EdgeInsets.all(16),
  277.               decoration: BoxDecoration(
  278.                 color: const Color(0xFF212529),
  279.                 borderRadius: BorderRadius.circular(24),
  280.                 boxShadow: [
  281.                   BoxShadow(
  282.                     color: Colors.black.withOpacity(0.15),
  283.                     blurRadius: 20,
  284.                     offset: const Offset(0, 8),
  285.                   ),
  286.                 ],
  287.               ),
  288.               child: ClipRRect(
  289.                 borderRadius: BorderRadius.circular(24),
  290.                 child: BottomNavigationBar(
  291.                   currentIndex: safeCurrentIndex,
  292.                   selectedItemColor: const Color(0xFFFFC727),
  293.                   unselectedItemColor: const Color(0xFF6C757D),
  294.                   backgroundColor: const Color(0xFF212529),
  295.                   type: BottomNavigationBarType.fixed,
  296.                   elevation: 0,
  297.                   onTap: (index) {
  298.                     setState(() {
  299.                       _selectedIndex = _bottomNavIndexes[index];
  300.                     });
  301.                   },
  302.                   selectedLabelStyle: const TextStyle(
  303.                     fontFamily: 'SansRegular',
  304.                     fontWeight: FontWeight.w600,
  305.                     fontSize: 12,
  306.                   ),
  307.                   unselectedLabelStyle: const TextStyle(
  308.                     fontFamily: 'SansRegular',
  309.                     fontWeight: FontWeight.w400,
  310.                     fontSize: 12,
  311.                   ),
  312.                   items: [
  313.                     BottomNavigationBarItem(
  314.                       icon: _buildBottomNavIcon(Icons.home_outlined, 0, safeCurrentIndex),
  315.                       activeIcon: _buildBottomNavIcon(Icons.home_rounded, 0, safeCurrentIndex),
  316.                       label: "Home",
  317.                     ),
  318.                     BottomNavigationBarItem(
  319.                       icon: _buildBottomNavIcon(Icons.inventory_2_outlined, 1, safeCurrentIndex),
  320.                       activeIcon: _buildBottomNavIcon(Icons.inventory_2_rounded, 1, safeCurrentIndex),
  321.                       label: "Inventory",
  322.                     ),
  323.                     BottomNavigationBarItem(
  324.                       icon: _buildBottomNavIcon(Icons.person_outline_rounded, 2, safeCurrentIndex),
  325.                       activeIcon: _buildBottomNavIcon(Icons.person_rounded, 2, safeCurrentIndex),
  326.                       label: "Account",
  327.                     ),
  328.                     BottomNavigationBarItem(
  329.                       icon: _buildBottomNavIcon(Icons.location_city_outlined, 3, safeCurrentIndex),
  330.                       activeIcon: _buildBottomNavIcon(Icons.location_city_rounded, 3, safeCurrentIndex),
  331.                       label: "Location",
  332.                     ),
  333.                   ],
  334.                 ),
  335.               ),
  336.             )
  337.           : null,
  338.     );
  339.   }
  340.  
  341.   Widget _buildDrawerItem(IconData icon, IconData activeIcon, String title, int index) {
  342.     final isSelected = _selectedIndex == index;
  343.  
  344.     return Container(
  345.       decoration: BoxDecoration(
  346.         color: isSelected ? const Color(0xFFFFC727).withOpacity(0.1) : Colors.transparent,
  347.         borderRadius: BorderRadius.circular(16),
  348.       ),
  349.       child: Material(
  350.         color: Colors.transparent,
  351.         child: InkWell(
  352.           borderRadius: BorderRadius.circular(16),
  353.           onTap: () => _onSelect(index),
  354.           child: Padding(
  355.             padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
  356.             child: Row(
  357.               children: [
  358.                 Container(
  359.                   padding: const EdgeInsets.all(8),
  360.                   decoration: BoxDecoration(
  361.                     color: isSelected
  362.                         ? const Color(0xFFFFC727)
  363.                         : const Color(0xFFF8F9FA),
  364.                     borderRadius: BorderRadius.circular(12),
  365.                   ),
  366.                   child: Icon(
  367.                     isSelected ? activeIcon : icon,
  368.                     color: isSelected
  369.                         ? const Color(0xFF212529)
  370.                         : const Color(0xFF6C757D),
  371.                     size: 20,
  372.                   ),
  373.                 ),
  374.                 const SizedBox(width: 16),
  375.                 Expanded(
  376.                   child: Text(
  377.                     title,
  378.                     style: TextStyle(
  379.                       color: isSelected
  380.                           ? const Color(0xFF212529)
  381.                           : const Color(0xFF6C757D),
  382.                       fontFamily: 'SansRegular',
  383.                       fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
  384.                       fontSize: 16,
  385.                     ),
  386.                   ),
  387.                 ),
  388.                 if (isSelected)
  389.                   Container(
  390.                     width: 6,
  391.                     height: 6,
  392.                     decoration: const BoxDecoration(
  393.                       color: Color(0xFFFFC727),
  394.                       shape: BoxShape.circle,
  395.                     ),
  396.                   ),
  397.               ],
  398.             ),
  399.           ),
  400.         ),
  401.       ),
  402.     );
  403.   }
  404.  
  405.   Widget _buildBottomNavIcon(IconData icon, int index, int currentIndex) {
  406.     final isSelected = index == currentIndex;
  407.    
  408.     return Container(
  409.       padding: const EdgeInsets.all(8),
  410.       decoration: BoxDecoration(
  411.         color: isSelected
  412.             ? const Color(0xFFFFC727).withOpacity(0.2)
  413.             : Colors.transparent,
  414.         borderRadius: BorderRadius.circular(12),
  415.       ),
  416.       child: Icon(
  417.         icon,
  418.         size: 24,
  419.         color: isSelected
  420.             ? const Color(0xFFFFC727)
  421.             : const Color(0xFF6C757D),
  422.       ),
  423.     );
  424.   }
  425. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement