home_screen.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. ),
  136. const Text(
  137. 'Producto',
  138. style: TextStyle(
  139. color: Colors.cyanAccent,
  140. fontWeight: FontWeight.bold,
  141. ),
  142. ),
  143. IconButton(
  144. icon: const Icon(Icons.favorite_border, color: Colors.white),
  145. onPressed: () {},
  146. ),
  147. ],
  148. )),
  149. backgroundColor: Colors.white,
  150. body: CustomScrollView(
  151. slivers: [
  152. SliverAppBar(
  153. floating: true,
  154. expandedHeight: 200, // Ajusta la altura para acomodar la imagen
  155. flexibleSpace: FlexibleSpaceBar(
  156. background: Image.asset(
  157. 'assets/turquessa_prop.jpg',
  158. fit: BoxFit.cover,
  159. ),
  160. ),
  161. bottom: PreferredSize(
  162. preferredSize:
  163. Size.fromHeight(120), // Altura del contenido adicional
  164. child: Container(
  165. color: Color.fromARGB(255, 47, 208, 229),
  166. padding:
  167. const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
  168. child: Row(
  169. children: [
  170. Container(
  171. width: 80,
  172. height: 80,
  173. decoration: BoxDecoration(
  174. color: Colors.white,
  175. borderRadius: BorderRadius.circular(12),
  176. ),
  177. child: Center(
  178. child: Image.asset('assets/Turquessa.png'),
  179. ),
  180. ),
  181. const SizedBox(width: 20),
  182. const Text(
  183. 'Turquessa-Coffee',
  184. style: TextStyle(
  185. color: Colors.black,
  186. fontSize: 26,
  187. fontWeight: FontWeight.bold,
  188. ),
  189. ),
  190. const SizedBox(width: 15),
  191. GestureDetector(
  192. onTap: () {
  193. mostrarInformacionNegocioBottomSheet(context);
  194. },
  195. child: Container(
  196. padding: const EdgeInsets.all(8),
  197. decoration: BoxDecoration(
  198. shape: BoxShape.circle,
  199. border: Border.all(color: Colors.white, width: 2),
  200. ),
  201. child: const Icon(Icons.info,
  202. color: Colors.white, size: 20),
  203. ),
  204. ),
  205. ],
  206. ),
  207. ),
  208. ),
  209. ),
  210. SliverPersistentHeader(
  211. delegate: CategoriasSliverChild(),
  212. pinned: true,
  213. ),
  214. const SliverToBoxAdapter(
  215. child: Center(
  216. child: Text('Coffee',
  217. style: TextStyle(
  218. fontSize: 40,
  219. fontWeight: FontWeight.bold,
  220. fontStyle: FontStyle.italic,
  221. )),
  222. ),
  223. ),
  224. SliverList(
  225. delegate: SliverChildBuilderDelegate(
  226. (context, index) {
  227. return _buildBurgerItem(
  228. items[index]['nombre'],
  229. items[index]['descripcion'],
  230. items[index]['precio'],
  231. items[index]['imageUrl'],
  232. context,
  233. );
  234. },
  235. childCount: items.length,
  236. ))
  237. ],
  238. ));
  239. }
  240. }
  241. class CategoriasSliverChild extends SliverPersistentHeaderDelegate {
  242. @override
  243. Widget build(
  244. BuildContext context, double shrinkOffset, bool overlapsContent) {
  245. return SingleChildScrollView(
  246. scrollDirection: Axis.horizontal, child: CategoriasNavBar());
  247. }
  248. @override
  249. double get maxExtent => 120.0;
  250. @override
  251. double get minExtent => 120.0;
  252. @override
  253. bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
  254. return false;
  255. }
  256. }
  257. Widget _buildBurgerItem(String nombre, String descripcion, String precio,
  258. String imageUrl, BuildContext context) {
  259. return GestureDetector(
  260. onTap: () {
  261. Navigator.of(context).pushNamed('producto');
  262. },
  263. child: Column(
  264. children: [
  265. Padding(
  266. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  267. child: Row(
  268. crossAxisAlignment: CrossAxisAlignment.center,
  269. children: [
  270. // Imagen con borde redondeado
  271. ClipRRect(
  272. borderRadius: BorderRadius.circular(10),
  273. child: Image.network(
  274. imageUrl,
  275. width: 100,
  276. height: 100,
  277. fit: BoxFit.cover,
  278. errorBuilder: (context, error, stackTrace) {
  279. return Container(
  280. width: 100,
  281. height: 100,
  282. color: Colors.grey[300],
  283. child: const Icon(Icons.restaurant,
  284. size: 40, color: Colors.grey),
  285. );
  286. },
  287. ),
  288. ),
  289. const SizedBox(width: 16),
  290. Expanded(
  291. child: Column(
  292. crossAxisAlignment: CrossAxisAlignment.start,
  293. children: [
  294. // Título con estilo más negrita
  295. Text(
  296. nombre,
  297. style: const TextStyle(
  298. color: Colors.black,
  299. fontSize: 20,
  300. fontWeight: FontWeight.w800,
  301. ),
  302. maxLines: 1,
  303. overflow: TextOverflow.ellipsis,
  304. ),
  305. const SizedBox(height: 6),
  306. // Descripción con color gris más claro
  307. Text(
  308. descripcion,
  309. style: TextStyle(
  310. color: Colors.grey[500],
  311. fontSize: 16,
  312. fontWeight: FontWeight.w400,
  313. ),
  314. maxLines: 2,
  315. overflow: TextOverflow.ellipsis,
  316. ),
  317. const SizedBox(height: 12),
  318. // Precio con estilo destacado
  319. Text(
  320. precio ?? 'Sin Precio',
  321. style: const TextStyle(
  322. color: Colors.black,
  323. fontSize: 22,
  324. fontWeight: FontWeight.bold,
  325. ),
  326. ),
  327. ],
  328. ),
  329. ),
  330. Icon(
  331. Icons.add_circle_outline,
  332. size: 28,
  333. color: Colors.grey[700],
  334. ),
  335. ],
  336. ),
  337. ),
  338. Divider(
  339. height: 1,
  340. thickness: 1,
  341. color: Colors.grey[300],
  342. ),
  343. ],
  344. ),
  345. );
  346. }