home_screen.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
  4. import 'package:turquessa_mesas_hoster/core/models/mesas_model.dart';
  5. import '../../viewmodels/viewmodels.dart';
  6. class HomeScreen extends StatefulWidget {
  7. const HomeScreen({super.key});
  8. @override
  9. Formulario createState() => Formulario();
  10. }
  11. class Formulario extends State<HomeScreen> {
  12. @override
  13. void initState() {
  14. super.initState();
  15. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  16. WidgetsBinding.instance.addPostFrameCallback((_) async {
  17. Provider.of<ProductoViewModel>(context, listen: false)
  18. .sincronizarProductosYCategorias();
  19. await mesaViewModel.sincronizarMesas();
  20. await mesaViewModel.fetchLocalAll(sinLimite: true, orderBy: 'nombre ASC');
  21. });
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. final mesaViewModel = Provider.of<MesaViewModel>(context);
  26. var _selectedIndex;
  27. return Scaffold(
  28. backgroundColor: Colors.grey.shade200,
  29. appBar: AppBar(
  30. title: const CustomAppbar(),
  31. ),
  32. body: Row(
  33. children: [
  34. NavigationRail(
  35. backgroundColor: Color.fromARGB(255, 25, 30, 41),
  36. selectedIndex: _selectedIndex,
  37. onDestinationSelected: (int index) {
  38. setState(() {
  39. _selectedIndex = index;
  40. });
  41. },
  42. labelType: NavigationRailLabelType.all,
  43. destinations: const [
  44. NavigationRailDestination(
  45. icon: Icon(Icons.home, color: Colors.white),
  46. selectedIcon: Icon(Icons.home_filled),
  47. label: Text('Inicio'),
  48. ),
  49. NavigationRailDestination(
  50. icon: Icon(Icons.search),
  51. selectedIcon: Icon(
  52. Icons.search_rounded,
  53. color: Colors.white,
  54. ),
  55. label: Text('Buscar'),
  56. ),
  57. NavigationRailDestination(
  58. icon: Icon(Icons.settings),
  59. selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
  60. label: Text('Ajustes'),
  61. ),
  62. ],
  63. ),
  64. Expanded(
  65. child: Center(
  66. child: GridView.builder(
  67. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  68. crossAxisCount: 4,
  69. childAspectRatio: 1.0,
  70. crossAxisSpacing: 10.0,
  71. mainAxisSpacing: 10.0,
  72. ),
  73. padding: const EdgeInsets.all(10),
  74. itemCount: mesaViewModel.mesas.length,
  75. itemBuilder: (context, index) {
  76. final mesa = mesaViewModel.mesas[index];
  77. return GestureDetector(
  78. onTap: () {
  79. mesaViewModel.selectMesa(mesa);
  80. },
  81. child: TableCard(
  82. icon: Icons.table_chart,
  83. //TODO: Agregar campo de estatus de la mesa para definir los colores
  84. color: (mesa.activa == true) ? Colors.blue : Colors.grey,
  85. title: mesa.nombre ?? 'Mesa sin nombre',
  86. ),
  87. );
  88. },
  89. ),
  90. ),
  91. ),
  92. //if (mesaViewModel.selectedMesa != null)
  93. Expanded(
  94. flex: 1,
  95. child: Container(
  96. margin: const EdgeInsets.all(10),
  97. decoration: BoxDecoration(
  98. color: Colors.white,
  99. borderRadius: BorderRadius.circular(10),
  100. boxShadow: [
  101. BoxShadow(
  102. color: Colors.grey.withOpacity(0.2),
  103. blurRadius: 5,
  104. spreadRadius: 1,
  105. )
  106. ],
  107. ),
  108. // child: TablaDetalles(table: selectedTable!),
  109. )),
  110. ],
  111. ),
  112. );
  113. }
  114. }
  115. class TableCard extends StatelessWidget {
  116. final IconData icon;
  117. final Color color;
  118. final String title;
  119. const TableCard(
  120. {super.key,
  121. required this.icon,
  122. required this.color,
  123. required this.title});
  124. @override
  125. Widget build(BuildContext context) {
  126. return Card(
  127. color: color,
  128. child: Column(
  129. mainAxisAlignment: MainAxisAlignment.center,
  130. children: [
  131. Icon(
  132. icon,
  133. size: 50,
  134. color: Colors.white,
  135. ),
  136. Text(
  137. title,
  138. style: const TextStyle(color: Colors.white, fontSize: 20),
  139. )
  140. ],
  141. ),
  142. );
  143. }
  144. }
  145. class TableDetailsPanel extends StatelessWidget {
  146. final TableItem table;
  147. const TableDetailsPanel({
  148. Key? key,
  149. required this.table,
  150. }) : super(key: key);
  151. @override
  152. Widget build(BuildContext context) {
  153. return Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. children: [
  156. // Encabezado del panel
  157. Container(
  158. padding: const EdgeInsets.all(16),
  159. decoration: BoxDecoration(
  160. borderRadius: const BorderRadius.vertical(top: Radius.circular(10)),
  161. ),
  162. child: Row(
  163. children: [
  164. Icon(Icons.person, color: Colors.white, size: 24),
  165. const SizedBox(width: 8),
  166. Text(
  167. table.name,
  168. style: const TextStyle(
  169. color: Colors.white,
  170. fontSize: 20,
  171. fontWeight: FontWeight.bold,
  172. ),
  173. ),
  174. ],
  175. ),
  176. ),
  177. // Contenido específico según el tipo
  178. ],
  179. );
  180. }
  181. }