home_screen.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:turquessa_mesas_hoster/core/models/producto_model.dart';
  4. import 'package:turquessa_mesas_hoster/mvvm/viewmodels/pedido_view_model.dart';
  5. import 'package:turquessa_mesas_hoster/mvvm/viewmodels/producto_view_model.dart';
  6. import 'package:turquessa_mesas_hoster/mvvm/views/home/carrito/carrito_screen.dart';
  7. import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
  8. import 'package:turquessa_mesas_hoster/mvvm/views/home/categorias_navbar.dart';
  9. import 'package:turquessa_mesas_hoster/mvvm/viewmodels/home_view_model.dart';
  10. import 'package:turquessa_mesas_hoster/utils/widgets/modal_infonegaocio.dart';
  11. import 'package:turquessa_mesas_hoster/mvvm/views/home/producto/producto_screen.dart';
  12. import 'package:turquessa_mesas_hoster/utils/widgets/widgets.dart';
  13. import 'package:turquessa_mesas_hoster/utils/widgets/horario_modal.dart';
  14. class HomeScreen extends StatefulWidget {
  15. const HomeScreen({Key? key}) : super(key: key);
  16. @override
  17. State<HomeScreen> createState() => _HomeScreenState();
  18. }
  19. class _HomeScreenState extends State<HomeScreen> {
  20. @override
  21. void initState() {
  22. super.initState();
  23. final homeViewModel = Provider.of<HomeViewModel>(context, listen: false);
  24. final productoViewModel =
  25. Provider.of<ProductoViewModel>(context, listen: false);
  26. setModalOffService(context);
  27. WidgetsBinding.instance.addPostFrameCallback((_) {
  28. Provider.of<ProductoViewModel>(context, listen: false)
  29. .sincronizarProductosYCategorias();
  30. homeViewModel.isHorarioServicio();
  31. homeViewModel.fetchLocalCategorias();
  32. homeViewModel
  33. .fetchLocalProductosPorCategoria(homeViewModel.selectedCategoria!);
  34. productoViewModel.sincronizarProductos();
  35. productoViewModel.sincronizarCategorias();
  36. productoViewModel.fetchLocalAll();
  37. });
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. final homeViewModel = Provider.of<HomeViewModel>(context, listen: false);
  42. final productos = homeViewModel.productos ?? [];
  43. return Scaffold(
  44. key: homeViewModel.scaffoldKey,
  45. drawer: const CustomDrawer(),
  46. bottomNavigationBar: BottomAppBar(
  47. color: Colors.black,
  48. child: Row(
  49. mainAxisAlignment: MainAxisAlignment.spaceAround,
  50. children: [
  51. IconButton(
  52. icon: const Icon(Icons.search, color: Colors.white),
  53. onPressed: () {
  54. homeViewModel.openDrawer();
  55. },
  56. ),
  57. IconButton(
  58. icon: const Icon(Icons.menu, color: Colors.white),
  59. onPressed: () {
  60. Navigator.of(context).pushNamed('carrito');
  61. },
  62. ),
  63. const Text(
  64. 'Producto',
  65. style: TextStyle(
  66. color: Colors.cyanAccent,
  67. fontWeight: FontWeight.bold,
  68. ),
  69. ),
  70. IconButton(
  71. icon: const Icon(Icons.favorite_border, color: Colors.white),
  72. onPressed: () {
  73. Navigator.of(context).pushNamed('perfil');
  74. },
  75. ),
  76. ],
  77. )),
  78. backgroundColor: Colors.white,
  79. body: CustomScrollView(
  80. slivers: [
  81. SliverAppBar(
  82. automaticallyImplyLeading: false,
  83. floating: true,
  84. expandedHeight: 200, // Ajusta la altura para acomodar la imagen
  85. flexibleSpace: FlexibleSpaceBar(
  86. background: Image.asset(
  87. 'assets/turquessa_prop.jpg',
  88. fit: BoxFit.cover,
  89. ),
  90. ),
  91. bottom: PreferredSize(
  92. preferredSize:
  93. Size.fromHeight(120), // Altura del contenido adicional
  94. child: Container(
  95. color: Color.fromARGB(255, 47, 208, 229),
  96. padding:
  97. const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
  98. child: Row(
  99. children: [
  100. Container(
  101. width: 80,
  102. height: 80,
  103. decoration: BoxDecoration(
  104. color: Colors.white,
  105. borderRadius: BorderRadius.circular(12),
  106. ),
  107. child: Center(
  108. child: Image.asset('assets/logo.png'),
  109. ),
  110. ),
  111. const SizedBox(width: 20),
  112. const Text(
  113. 'Turquessa-Coffee',
  114. style: TextStyle(
  115. color: Colors.black,
  116. fontSize: 26,
  117. fontWeight: FontWeight.bold,
  118. ),
  119. ),
  120. const SizedBox(width: 15),
  121. GestureDetector(
  122. onTap: () {
  123. mostrarInformacionNegocioBottomSheet(context);
  124. },
  125. child: Container(
  126. padding: const EdgeInsets.all(8),
  127. decoration: BoxDecoration(
  128. shape: BoxShape.circle,
  129. border: Border.all(color: Colors.white, width: 2),
  130. ),
  131. child: const Icon(Icons.info,
  132. color: Colors.white, size: 20),
  133. ),
  134. ),
  135. ],
  136. ),
  137. ),
  138. ),
  139. ),
  140. SliverPersistentHeader(
  141. delegate: CategoriasSliverChild(),
  142. pinned: true,
  143. ),
  144. const SliverToBoxAdapter(
  145. child: Center(
  146. child: Text('Coffee',
  147. style: TextStyle(
  148. fontSize: 40,
  149. fontWeight: FontWeight.bold,
  150. fontStyle: FontStyle.italic,
  151. )),
  152. ),
  153. ),
  154. SliverList(
  155. delegate: SliverChildBuilderDelegate(
  156. (context, index) {
  157. productos.isEmpty
  158. ? _buildBurgerItem(
  159. productos[index].nombre!,
  160. productos[index].descripcion!,
  161. productos[index].precio.toString(),
  162. productos[index].media![0].ruta! ?? ' ',
  163. context,
  164. )
  165. : const Center(
  166. child: CircularProgressIndicator(),
  167. );
  168. },
  169. childCount: items.length,
  170. ))
  171. ],
  172. ));
  173. }
  174. }
  175. class CategoriasSliverChild extends SliverPersistentHeaderDelegate {
  176. @override
  177. Widget build(
  178. BuildContext context, double shrinkOffset, bool overlapsContent) {
  179. return CategoriasNavBar();
  180. }
  181. @override
  182. double get maxExtent => 120.0;
  183. @override
  184. double get minExtent => 120.0;
  185. @override
  186. bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
  187. return false;
  188. }
  189. }
  190. Widget _buildBurgerItem(String nombre, String descripcion, String precio,
  191. String imageUrl, BuildContext context) {
  192. return GestureDetector(
  193. onTap: () {
  194. Navigator.of(context).pushNamed('producto');
  195. },
  196. child: Column(
  197. children: [
  198. Padding(
  199. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  200. child: Row(
  201. crossAxisAlignment: CrossAxisAlignment.center,
  202. children: [
  203. // Imagen con borde redondeado
  204. ClipRRect(
  205. borderRadius: BorderRadius.circular(10),
  206. child: Image.network(
  207. imageUrl,
  208. width: 100,
  209. height: 100,
  210. fit: BoxFit.cover,
  211. errorBuilder: (context, error, stackTrace) {
  212. return Container(
  213. width: 100,
  214. height: 100,
  215. color: Colors.grey[300],
  216. child: const Icon(Icons.restaurant,
  217. size: 40, color: Colors.grey),
  218. );
  219. },
  220. ),
  221. ),
  222. const SizedBox(width: 16),
  223. Expanded(
  224. child: Column(
  225. crossAxisAlignment: CrossAxisAlignment.start,
  226. children: [
  227. // Título con estilo más negrita
  228. Text(
  229. nombre,
  230. style: const TextStyle(
  231. color: Colors.black,
  232. fontSize: 20,
  233. fontWeight: FontWeight.w800,
  234. ),
  235. maxLines: 1,
  236. overflow: TextOverflow.ellipsis,
  237. ),
  238. const SizedBox(height: 6),
  239. // Descripción con color gris más claro
  240. Text(
  241. descripcion,
  242. style: TextStyle(
  243. color: Colors.grey[500],
  244. fontSize: 16,
  245. fontWeight: FontWeight.w400,
  246. ),
  247. maxLines: 2,
  248. overflow: TextOverflow.ellipsis,
  249. ),
  250. const SizedBox(height: 12),
  251. // Precio con estilo destacado
  252. Text(
  253. precio ?? 'Sin Precio',
  254. style: const TextStyle(
  255. color: Colors.black,
  256. fontSize: 22,
  257. fontWeight: FontWeight.bold,
  258. ),
  259. ),
  260. ],
  261. ),
  262. ),
  263. Icon(
  264. Icons.add_circle_outline,
  265. size: 28,
  266. color: Colors.grey[700],
  267. ),
  268. ],
  269. ),
  270. ),
  271. Divider(
  272. height: 1,
  273. thickness: 1,
  274. color: Colors.grey[300],
  275. ),
  276. ],
  277. ),
  278. );
  279. }