app_drawer.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // ignore_for_file: must_be_immutable
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:sis_flutter/views/home/home_screen.dart';
  5. import '../models/usuario_model.dart';
  6. import '../themes/themes.dart';
  7. import '../viewmodels/administracion_view_model.dart';
  8. import '../viewmodels/login_view_model.dart';
  9. import '../views/main/main_screen.dart';
  10. import 'widgets_components.dart';
  11. class AppDrawer extends StatelessWidget {
  12. AppDrawer({super.key});
  13. Future<bool> _showExitConfirmationDialog(BuildContext context) async {
  14. bool shouldPop = false;
  15. await showDialog(
  16. context: context,
  17. builder: (context) => AlertDialog(
  18. surfaceTintColor: AppTheme.secondary,
  19. title: const Text('¿Cerrar sesión?'),
  20. content: const Text('¿Estás seguro de que quieres cerrar la sesión?'),
  21. actions: [
  22. TextButton(
  23. onPressed: () => Navigator.of(context).pop(false),
  24. child: const Text('Cancelar', style: TextStyle(color: Colors.red)),
  25. ),
  26. TextButton(
  27. onPressed: () {
  28. Navigator.pop(context);
  29. Navigator.pop(context);
  30. Provider.of<LoginViewModel>(context, listen: false).logOut();
  31. Navigator.of(context)
  32. .pushNamedAndRemoveUntil(MainScreen.route, (route) => false);
  33. },
  34. child: const Text('Aceptar'),
  35. ),
  36. ],
  37. ),
  38. );
  39. return shouldPop;
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. String? nombre = Provider.of<LoginViewModel>(context).nombre.toString();
  44. String? correo = Provider.of<LoginViewModel>(context).correo.toString();
  45. final avm = Provider.of<AdministracionViewModel>(context);
  46. List<String> permisos = avm.lospermisos;
  47. return Drawer(
  48. surfaceTintColor: Colors.white,
  49. backgroundColor: Colors.white,
  50. child: Column(
  51. children: [
  52. Container(
  53. width: double.infinity,
  54. decoration: BoxDecoration(
  55. color: AppTheme.primary,
  56. ),
  57. padding: EdgeInsets.only(
  58. top: MediaQuery.of(context).padding.top,
  59. ),
  60. child: Column(
  61. children: [
  62. const Padding(
  63. padding: EdgeInsets.all(8.0),
  64. child: Image(
  65. image: AssetImage('assets/edesarrollos_logo.png'),
  66. height: 200,
  67. ),
  68. ),
  69. const SizedBox(
  70. height: 10,
  71. ),
  72. Text(
  73. nombre.toString(),
  74. style: const TextStyle(
  75. fontSize: 18,
  76. fontWeight: FontWeight.bold,
  77. ),
  78. ),
  79. const SizedBox(
  80. height: 10,
  81. ),
  82. Text(
  83. correo.toString(),
  84. style: const TextStyle(
  85. fontSize: 15,
  86. fontWeight: FontWeight.bold,
  87. ),
  88. ),
  89. const SizedBox(
  90. height: 10,
  91. ),
  92. ],
  93. ),
  94. ),
  95. //HEADER
  96. Expanded(
  97. child: ListView(padding: EdgeInsets.zero, children: [
  98. ListTile(
  99. leading: circulo(const Icon(Icons.home_filled)),
  100. title: const Text('Inicio'),
  101. onTap: () {
  102. Navigator.pop(context);
  103. Navigator.of(context).pushNamed(HomeScreen.route);
  104. },
  105. ),
  106. ListTile(
  107. leading: const Icon(Icons.logout),
  108. title: const Text('Cerrar sesión'),
  109. onTap: () {
  110. _showExitConfirmationDialog(context);
  111. },
  112. ),
  113. ])),
  114. const Padding(
  115. padding: EdgeInsets.only(bottom: 10),
  116. child: Align(
  117. alignment: Alignment.bottomCenter,
  118. child: Text(
  119. 'v1.24.10.29+1',
  120. style: TextStyle(fontWeight: FontWeight.w300),
  121. ),
  122. ))
  123. ],
  124. ),
  125. );
  126. }
  127. }