home_screen.dart 12 KB

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