home_screen.dart 13 KB

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