navigation_rail.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. backgroundColor: Color.fromARGB(255, 25, 30, 41),
  15. selectedIndex: selectedIndex,
  16. onDestinationSelected: (int index) {
  17. setState(() {
  18. selectedIndex = index;
  19. });
  20. if (index == 3) {
  21. Provider.of<LoginViewModel>(context, listen: false)
  22. .showExitConfirmationDialog(context);
  23. }
  24. },
  25. labelType: NavigationRailLabelType.all,
  26. destinations: const [
  27. NavigationRailDestination(
  28. icon: Icon(Icons.home, color: Colors.white),
  29. selectedIcon: Icon(Icons.home_filled),
  30. label: Text('Inicio'),
  31. ),
  32. NavigationRailDestination(
  33. icon: Icon(Icons.search),
  34. selectedIcon: Icon(
  35. Icons.search_rounded,
  36. color: Colors.white,
  37. ),
  38. label: Text('Buscar'),
  39. ),
  40. NavigationRailDestination(
  41. icon: Icon(Icons.settings),
  42. selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
  43. label: Text('Ajustes'),
  44. ),
  45. NavigationRailDestination(
  46. icon: Icon(Icons.logout),
  47. selectedIcon: Icon(Icons.logout, color: Colors.white),
  48. label: Text('Cerrar Sesión'),
  49. ),
  50. ],
  51. );
  52. }
  53. }