home_screen.dart 13 KB

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