home_screen.dart 11 KB

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