app_drawer.dart 4.6 KB

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