app_drawer.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // ignore_for_file: must_be_immutable
  2. import 'package:flutter/material.dart';
  3. import 'package:yoshi_papas_app/views/categoria_producto/categoria_producto_screen.dart';
  4. import 'package:yoshi_papas_app/views/pedido/pedido_screen.dart';
  5. import 'package:yoshi_papas_app/views/producto/producto_screen.dart';
  6. import 'package:yoshi_papas_app/views/sucursal/sucursal_screen.dart';
  7. import 'package:yoshi_papas_app/views/variable/variable_screen.dart';
  8. import 'package:yoshi_papas_app/views/venta/venta_screen.dart';
  9. import 'package:provider/provider.dart';
  10. import '../models/models.dart';
  11. import '../themes/themes.dart';
  12. import '../viewmodels/login_view_model.dart';
  13. import '../viewmodels/viewmodels.dart';
  14. import '../views/descuento/descuento_screen.dart';
  15. import 'widgets_components.dart';
  16. class AppDrawer extends StatelessWidget {
  17. AppDrawer({super.key});
  18. Future<bool> _showExitConfirmationDialog(BuildContext context) async {
  19. bool shouldPop = false;
  20. await showDialog(
  21. context: context,
  22. builder: (context) => AlertDialog(
  23. surfaceTintColor: AppTheme.secondary,
  24. title: const Text('¿Cerrar sesión?'),
  25. content: const Text('¿Estás seguro de que quieres cerrar la sesión?'),
  26. actions: [
  27. TextButton(
  28. onPressed: () => Navigator.of(context).pop(false),
  29. child: const Text('Cancelar', style: TextStyle(color: Colors.red)),
  30. ),
  31. TextButton(
  32. onPressed: () async {
  33. Provider.of<LoginViewModel>(context, listen: false).logOut();
  34. Navigator.of(context).pushNamedAndRemoveUntil(
  35. 'login',
  36. (route) => false,
  37. );
  38. },
  39. child: const Text('Aceptar'),
  40. ),
  41. ],
  42. ),
  43. );
  44. return shouldPop;
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. final permisoViewModel = Provider.of<PermisoViewModel>(context);
  49. final userPermisos = permisoViewModel.userPermisos;
  50. return Drawer(
  51. surfaceTintColor: Colors.white,
  52. backgroundColor: Colors.white,
  53. child: Column(
  54. children: [
  55. Container(
  56. width: double.infinity,
  57. decoration: BoxDecoration(
  58. color: AppTheme.primary,
  59. ),
  60. padding: EdgeInsets.only(
  61. top: MediaQuery.of(context).padding.top,
  62. ),
  63. child: const Column(
  64. children: [
  65. Padding(
  66. padding: EdgeInsets.all(8.0),
  67. child: Image(
  68. image: AssetImage('assets/JoshiLogoHorizontal.png'),
  69. height: 150,
  70. ),
  71. ),
  72. SizedBox(
  73. height: 10,
  74. ),
  75. SizedBox(
  76. height: 10,
  77. ),
  78. ],
  79. ),
  80. ),
  81. // HEADER
  82. Expanded(
  83. child: ListView(
  84. children: [
  85. ListTile(
  86. leading: circulo(const Icon(Icons.restaurant_menu)),
  87. title: const Text('Pedidos'),
  88. onTap: () => {
  89. Navigator.pop(context),
  90. Navigator.of(context).push(
  91. MaterialPageRoute(
  92. builder: (context) => const PedidoScreen(),
  93. ),
  94. ),
  95. },
  96. ),
  97. ListTile(
  98. leading: circulo(const Icon(Icons.menu_book_rounded)),
  99. title: const Text('Productos'),
  100. onTap: () => {
  101. Navigator.pop(context),
  102. Navigator.of(context).push(
  103. MaterialPageRoute(
  104. builder: (context) => ProductoScreen(),
  105. ),
  106. ),
  107. },
  108. ),
  109. if (userPermisos.contains(Usuario.VER_CATEGORIAS))
  110. ListTile(
  111. leading:
  112. circulo(const Icon(Icons.format_list_bulleted_rounded)),
  113. title: const Text('Categoría Producto'),
  114. onTap: () => {
  115. Navigator.pop(context),
  116. Navigator.of(context).push(
  117. MaterialPageRoute(
  118. builder: (context) => CategoriaProductoScreen(),
  119. ),
  120. ),
  121. },
  122. ),
  123. ListTile(
  124. leading: circulo(const Icon(Icons.receipt_long_outlined)),
  125. title: const Text('Pedidos Por Día'),
  126. onTap: () => {
  127. Navigator.pop(context),
  128. Navigator.of(context).push(
  129. MaterialPageRoute(
  130. builder: (context) => VentaScreen(),
  131. ),
  132. ),
  133. },
  134. ),
  135. ExpansionTile(
  136. leading: circulo(const Icon(Icons.admin_panel_settings)),
  137. title: const Text('Administración'),
  138. children: [
  139. ListTile(
  140. leading: circulo(const Icon(Icons.discount)),
  141. title: const Text('Descuentos'),
  142. onTap: () => {
  143. Navigator.pop(context),
  144. Navigator.of(context).push(
  145. MaterialPageRoute(
  146. builder: (context) => DescuentoScreen(),
  147. ),
  148. ),
  149. },
  150. ),
  151. ListTile(
  152. leading: circulo(const Icon(Icons.discount)),
  153. title: const Text('Variables'),
  154. onTap: () => {
  155. Navigator.pop(context),
  156. Navigator.of(context).push(
  157. MaterialPageRoute(
  158. builder: (context) => VariablesScreen(),
  159. ),
  160. ),
  161. },
  162. ),
  163. if (userPermisos.contains(Usuario.VER_SUCURSALES))
  164. ListTile(
  165. leading: circulo(const Icon(Icons.storefront_outlined)),
  166. title: const Text('Sucursales'),
  167. onTap: () => {
  168. Navigator.pop(context),
  169. Navigator.of(context).push(
  170. MaterialPageRoute(
  171. builder: (context) => SucursalesPage(),
  172. ),
  173. ),
  174. },
  175. ),
  176. ],
  177. ),
  178. ListTile(
  179. leading: const Icon(Icons.logout),
  180. title: const Text('Cerrar sesión'),
  181. onTap: () {
  182. _showExitConfirmationDialog(context);
  183. },
  184. ),
  185. ],
  186. ),
  187. ),
  188. Padding(
  189. padding: const EdgeInsets.only(bottom: 10),
  190. child: Align(
  191. alignment: Alignment.bottomCenter,
  192. child: Text(
  193. 'v1.24.10.09+1',
  194. style: const TextStyle(fontWeight: FontWeight.w300),
  195. ),
  196. ),
  197. ),
  198. ],
  199. ),
  200. );
  201. }
  202. }