app_drawer.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // ignore_for_file: must_be_immutable
  2. import 'package:conalep_pos/models/models.dart';
  3. import 'package:conalep_pos/views/categoria_producto/categoria_producto_screen.dart';
  4. import 'package:conalep_pos/views/corte_caja/corte_caja_screen.dart';
  5. import 'package:conalep_pos/views/pedido/pedido_screen.dart';
  6. import 'package:conalep_pos/views/producto/producto_screen.dart';
  7. import 'package:conalep_pos/views/venta/venta_screen.dart';
  8. import 'package:flutter/material.dart';
  9. import '../models/usuario_model.dart';
  10. import 'package:provider/provider.dart';
  11. import '../services/repo_service.dart';
  12. import '../services/services.dart';
  13. import '../themes/themes.dart';
  14. import '../viewmodels/login_view_model.dart';
  15. import '../viewmodels/permiso_view_model.dart';
  16. import '../views/descuento/descuento_screen.dart';
  17. import '../views/sucursal/sucursal_screen.dart';
  18. import '../views/variable/variable_screen.dart';
  19. import 'widgets_components.dart';
  20. import 'copia_db.dart';
  21. class AppDrawer extends StatelessWidget {
  22. AppDrawer({super.key});
  23. Future<bool> _showExitConfirmationDialog(BuildContext context) async {
  24. bool shouldPop = false;
  25. await showDialog(
  26. context: context,
  27. builder: (context) => AlertDialog(
  28. surfaceTintColor: AppTheme.secondary,
  29. title: const Text('¿Cerrar sesión?'),
  30. content: const Text('¿Estás seguro de que quieres cerrar la sesión?'),
  31. actions: [
  32. TextButton(
  33. onPressed: () => Navigator.of(context).pop(false),
  34. child: const Text('Cancelar', style: TextStyle(color: Colors.red)),
  35. ),
  36. TextButton(
  37. onPressed: () async {
  38. Provider.of<LoginViewModel>(context, listen: false).logOut();
  39. Navigator.of(context).pushNamedAndRemoveUntil(
  40. 'login',
  41. (route) => false,
  42. );
  43. },
  44. child: const Text('Aceptar'),
  45. ),
  46. ],
  47. ),
  48. );
  49. return shouldPop;
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. final permisoViewModel = Provider.of<PermisoViewModel>(context);
  54. List<String> userPermisos = permisoViewModel.userPermisos;
  55. BaseService baseService = BaseService(); // Instancia de BaseService
  56. String prefijoVersion = baseService.prefijoVersion();
  57. return Drawer(
  58. surfaceTintColor: Colors.white,
  59. backgroundColor: Colors.white,
  60. child: Column(
  61. children: [
  62. Container(
  63. width: double.infinity,
  64. decoration: BoxDecoration(
  65. color: AppTheme.primary,
  66. ),
  67. padding: EdgeInsets.only(
  68. top: MediaQuery.of(context).padding.top,
  69. ),
  70. child: const Column(
  71. children: [
  72. Padding(
  73. padding: EdgeInsets.all(8.0),
  74. child: Image(
  75. image: AssetImage('assets/icono-BN.png'),
  76. height: 150,
  77. ),
  78. ),
  79. SizedBox(
  80. height: 10,
  81. ),
  82. SizedBox(
  83. height: 10,
  84. ),
  85. ],
  86. ),
  87. ),
  88. // HEADER
  89. Expanded(
  90. child: ListView(
  91. children: [
  92. ListTile(
  93. leading: circulo(const Icon(Icons.restaurant_menu)),
  94. title: const Text('Pedidos'),
  95. onTap: () => {
  96. Navigator.pop(context),
  97. Navigator.of(context).push(
  98. MaterialPageRoute(
  99. builder: (context) => const PedidoScreen(),
  100. ),
  101. ),
  102. },
  103. ),
  104. ListTile(
  105. leading: circulo(const Icon(Icons.menu_book_rounded)),
  106. title: const Text('Productos'),
  107. onTap: () => {
  108. Navigator.pop(context),
  109. Navigator.of(context).push(
  110. MaterialPageRoute(
  111. builder: (context) => ProductoScreen(),
  112. ),
  113. ),
  114. },
  115. ),
  116. //if (userPermisos.contains(Usuario.VER_CATEGORIAS))
  117. ListTile(
  118. leading:
  119. circulo(const Icon(Icons.format_list_bulleted_rounded)),
  120. title: const Text('Categoría Producto'),
  121. onTap: () => {
  122. Navigator.pop(context),
  123. Navigator.of(context).push(
  124. MaterialPageRoute(
  125. builder: (context) => CategoriaProductoScreen(),
  126. ),
  127. ),
  128. },
  129. ),
  130. ListTile(
  131. leading: circulo(const Icon(Icons.receipt_long_outlined)),
  132. title: const Text('Pedidos Por Día'),
  133. onTap: () => {
  134. Navigator.pop(context),
  135. Navigator.of(context).push(
  136. MaterialPageRoute(
  137. builder: (context) => VentaScreen(),
  138. ),
  139. ),
  140. },
  141. ),
  142. //if (userPermisos.contains(Usuario.VER_ADMIN))
  143. ExpansionTile(
  144. leading: circulo(const Icon(Icons.admin_panel_settings)),
  145. title: const Text('Administración'),
  146. children: [
  147. ListTile(
  148. leading: circulo(const Icon(Icons.point_of_sale)),
  149. title: const Text('Corte de caja'),
  150. onTap: () => {
  151. Navigator.pop(context),
  152. Navigator.of(context).push(
  153. MaterialPageRoute(
  154. builder: (context) => CorteCajaScreen(),
  155. ),
  156. ),
  157. },
  158. ),
  159. ListTile(
  160. leading: circulo(const Icon(Icons.discount)),
  161. title: const Text('Descuentos'),
  162. onTap: () => {
  163. Navigator.pop(context),
  164. Navigator.of(context).push(
  165. MaterialPageRoute(
  166. builder: (context) => DescuentoScreen(),
  167. ),
  168. ),
  169. },
  170. ),
  171. ListTile(
  172. leading: circulo(const Icon(Icons.discount)),
  173. title: const Text('Variables'),
  174. onTap: () => {
  175. Navigator.pop(context),
  176. Navigator.of(context).push(
  177. MaterialPageRoute(
  178. builder: (context) => VariablesScreen(),
  179. ),
  180. ),
  181. },
  182. ),
  183. //if (userPermisos.contains(Usuario.VER_SUCURSALES))
  184. ListTile(
  185. leading: circulo(const Icon(Icons.storefront_outlined)),
  186. title: const Text('Sucursales'),
  187. onTap: () => {
  188. Navigator.pop(context),
  189. Navigator.of(context).push(
  190. MaterialPageRoute(
  191. builder: (context) => SucursalesPage(),
  192. ),
  193. ),
  194. },
  195. ),
  196. //if (userPermisos.contains(Usuario.FORZAR_SINCRONIZACION))
  197. ListTile(
  198. leading: circulo(const Icon(Icons.sync)),
  199. title: const Text('Forzar Sincronización'),
  200. onTap: () async {
  201. bool confirmado = await showDialog(
  202. context: context,
  203. builder: (context) {
  204. return AlertDialog(
  205. title: const Text("Forzar Sincronización",
  206. style: TextStyle(
  207. fontWeight: FontWeight.w500,
  208. fontSize: 22)),
  209. content: const Text(
  210. '¿Estás seguro de que deseas forzar la sincronización?',
  211. style: TextStyle(fontSize: 18)),
  212. actions: [
  213. Row(
  214. mainAxisAlignment:
  215. MainAxisAlignment.spaceBetween,
  216. children: [
  217. TextButton(
  218. onPressed: () =>
  219. Navigator.of(context).pop(false),
  220. child: const Text('No',
  221. style: TextStyle(fontSize: 18)),
  222. style: ButtonStyle(
  223. padding: MaterialStateProperty.all(
  224. EdgeInsets.fromLTRB(
  225. 20, 10, 20, 10)),
  226. backgroundColor:
  227. MaterialStateProperty.all(
  228. Colors.red),
  229. foregroundColor:
  230. MaterialStateProperty.all(
  231. AppTheme.secondary),
  232. ),
  233. ),
  234. TextButton(
  235. onPressed: () =>
  236. Navigator.of(context).pop(true),
  237. child: const Text('Sí',
  238. style: TextStyle(fontSize: 18)),
  239. style: ButtonStyle(
  240. padding: MaterialStateProperty.all(
  241. EdgeInsets.fromLTRB(
  242. 20, 10, 20, 10)),
  243. backgroundColor:
  244. MaterialStateProperty.all(
  245. AppTheme.tertiary),
  246. foregroundColor:
  247. MaterialStateProperty.all(
  248. AppTheme.quaternary),
  249. ),
  250. ),
  251. ],
  252. ),
  253. ],
  254. );
  255. },
  256. ) ??
  257. false;
  258. if (confirmado) {
  259. showDialog(
  260. context: context,
  261. barrierDismissible: false,
  262. builder: (context) => AlertDialog(
  263. title: const Text("Sincronizando",
  264. style: TextStyle(
  265. fontWeight: FontWeight.w500,
  266. fontSize: 22)),
  267. content: Padding(
  268. padding: const EdgeInsetsDirectional.symmetric(
  269. horizontal: 120),
  270. child: const CircularProgressIndicator(),
  271. ),
  272. ),
  273. );
  274. try {
  275. await RepoService().forzarSincronizacion();
  276. Navigator.of(context, rootNavigator: true).pop();
  277. Navigator.of(context).pop();
  278. ScaffoldMessenger.of(context).showSnackBar(
  279. SnackBar(
  280. content: const Text(
  281. 'Sincronización completada con éxito'),
  282. backgroundColor: Colors.green,
  283. ),
  284. );
  285. } catch (e) {
  286. Navigator.of(context, rootNavigator: true).pop();
  287. Navigator.of(context).pop();
  288. ScaffoldMessenger.of(context).showSnackBar(
  289. SnackBar(
  290. content: Text('Error en la sincronización: $e'),
  291. backgroundColor: Colors.red,
  292. ),
  293. );
  294. }
  295. }
  296. },
  297. ),
  298. ],
  299. ),
  300. ListTile(
  301. leading: const Icon(Icons.logout),
  302. title: const Text('Cerrar sesión'),
  303. onTap: () {
  304. _showExitConfirmationDialog(context);
  305. },
  306. ),
  307. ],
  308. ),
  309. ),
  310. Padding(
  311. padding: const EdgeInsets.only(bottom: 10),
  312. child: Align(
  313. alignment: Alignment.bottomCenter,
  314. child: Text(
  315. '$prefijoVersion.1.24.11.08',
  316. style: const TextStyle(fontWeight: FontWeight.w300),
  317. ),
  318. ),
  319. ),
  320. ],
  321. ),
  322. );
  323. }
  324. }