home_screen.dart 12 KB

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