home_screen.dart 12 KB

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