navigation_rail.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import '../../mvvm/viewmodels/viewmodels.dart';
  4. class CustomNavigationRail extends StatefulWidget {
  5. const CustomNavigationRail({super.key, required selectedIndex});
  6. @override
  7. State<CustomNavigationRail> createState() => Custom_NavigationRailState();
  8. }
  9. class Custom_NavigationRailState extends State<CustomNavigationRail> {
  10. int selectedIndex = 0;
  11. @override
  12. Widget build(BuildContext context) {
  13. return NavigationRail(
  14. minExtendedWidth: 100,
  15. minWidth: 30,
  16. backgroundColor: Color.fromARGB(255, 25, 30, 41),
  17. selectedIndex: selectedIndex,
  18. onDestinationSelected: (int index) {
  19. setState(() {
  20. selectedIndex = index;
  21. });
  22. if (index == 3) {
  23. Provider.of<LoginViewModel>(context, listen: false)
  24. .showExitConfirmationDialog(context);
  25. }
  26. },
  27. labelType: NavigationRailLabelType.all,
  28. destinations: const [
  29. NavigationRailDestination(
  30. icon: Icon(Icons.home, color: Colors.white),
  31. selectedIcon: Icon(Icons.home_filled),
  32. label: Text('Inicio'),
  33. ),
  34. NavigationRailDestination(
  35. icon: Icon(Icons.search),
  36. selectedIcon: Icon(
  37. Icons.search_rounded,
  38. color: Colors.white,
  39. ),
  40. label: Text('Buscar'),
  41. ),
  42. NavigationRailDestination(
  43. icon: Icon(Icons.settings),
  44. selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
  45. label: Text('Ajustes'),
  46. ),
  47. NavigationRailDestination(
  48. icon: Icon(Icons.logout),
  49. selectedIcon: Icon(Icons.logout, color: Colors.white),
  50. label: Text('Cerrar Sesión'),
  51. ),
  52. ],
  53. );
  54. }
  55. }