123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
- import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
- import 'package:turquessa_mesas_hoster/utils/widgets/custom_card.dart';
- import 'package:turquessa_mesas_hoster/utils/widgets/get_status_style.dart';
- import 'package:turquessa_mesas_hoster/utils/widgets/navigation_rail.dart';
- import '../../../utils/widgets/ordenes_card.dart';
- import '../../viewmodels/viewmodels.dart';
- class HomeScreen extends StatefulWidget {
- const HomeScreen({super.key});
- @override
- Formulario createState() => Formulario();
- }
- class Formulario extends State<HomeScreen> {
- int _selectedIndex = 0;
- @override
- void initState() {
- super.initState();
- final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
- WidgetsBinding.instance.addPostFrameCallback((_) async {
- Provider.of<ProductoViewModel>(context, listen: false)
- .sincronizarProductosYCategorias();
- await mesaViewModel.sincronizarMesas();
- await mesaViewModel.fetchLocal();
- });
- }
- @override
- Widget build(BuildContext context) {
- final mesaViewModel = Provider.of<MesaViewModel>(context);
- final loginViewModel = Provider.of<LoginViewModel>(context);
- var _selectedIndex;
- return Scaffold(
- backgroundColor: Colors.grey.shade200,
- appBar: AppBar(
- title: const CustomAppbar(),
- ),
- body: Container(
- decoration: const BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [
- Color(0xFFE0F7FA),
- Color(0xFFB2EBF2),
- Color(0xFF80DEEA),
- Color(0xFF4DD0E1),
- ],
- ),
- ),
- child: Row(
- children: [
- CustomNavigationRail(selectedIndex: _selectedIndex),
- Expanded(
- flex: 1,
- child: Center(
- child: Container(
- decoration: const BoxDecoration(
- color: Colors.white,
- ),
- child: GridView.builder(
- gridDelegate:
- const SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3,
- childAspectRatio: 1.0,
- crossAxisSpacing: 10.0,
- mainAxisSpacing: 10.0,
- ),
- padding: const EdgeInsets.all(10),
- itemCount: mesaViewModel.mesas.length,
- itemBuilder: (context, index) {
- final mesa = mesaViewModel.mesas[index];
- return GestureDetector(
- onTap: () {
- setState(() {
- mesaViewModel.selectMesa(mesa);
- });
- },
- child: TableCard(
- mesa: mesa,
- ),
- );
- },
- ),
- ),
- ),
- ),
- if (mesaViewModel.selectedMesa != null)
- Expanded(
- child: Container(
- margin: const EdgeInsets.symmetric(horizontal: 10),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(10),
- boxShadow: [
- BoxShadow(
- color: Colors.grey.withOpacity(0.2),
- blurRadius: 5,
- spreadRadius: 1,
- )
- ],
- ),
- child: TablaDetalles(
- status: EstadoPedido.disponible,
- table: mesaViewModel.selectedMesa ??
- Mesa(
- activa: false,
- id: 0,
- nombre: 'Mesa sin nombre',
- estado: EstadoPedido.disponible)),
- )),
- ],
- ),
- ),
- );
- }
- }
- class TablaDetalles extends StatelessWidget {
- final Mesa table;
- final EstadoPedido status;
- const TablaDetalles({
- Key? key,
- required this.table,
- required this.status,
- }) : super(key: key);
- @override
- Widget build(BuildContext context) {
- final mesaViewModel = Provider.of<MesaViewModel>(context, listen: true);
- final style = getStatusStyle(status);
- return Container(
- decoration: BoxDecoration(
- color: Color.fromARGB(255, 247, 249, 250),
- boxShadow: [
- BoxShadow(
- color: Colors.grey.withOpacity(0.2),
- blurRadius: 5,
- spreadRadius: 1,
- )
- ],
- ),
- child: Column(
- children: [
- // Header
- Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: style.iconColor,
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- const Icon(Icons.table_restaurant,
- color: Colors.white, size: 24),
- const SizedBox(width: 8),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- table.nombre ?? 'Mesa sin nombre',
- style: const TextStyle(
- color: Colors.white,
- fontSize: 20,
- fontWeight: FontWeight.bold,
- ),
- ),
- const Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(
- Icons.access_time_rounded,
- color: Colors.white70,
- size: 16,
- ),
- Padding(
- padding: EdgeInsets.only(left: 4),
- child: Text(
- "03:56",
- style: TextStyle(
- fontSize: 14,
- color: Colors.white,
- fontWeight: FontWeight.normal,
- ),
- ),
- ),
- ],
- )
- ],
- ),
- ],
- ),
- Container(
- padding:
- const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
- decoration: BoxDecoration(
- color: Colors.white.withOpacity(0.2),
- borderRadius: BorderRadius.circular(20),
- ),
- child: GestureDetector(
- onTap: () {
- mesaViewModel.cambiarEstadoPedidoMesa(style.nextStatus);
- },
- child: Text(table.activa! ? 'Activa' : 'Inactiva',
- style: const TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.bold,
- )),
- ),
- ),
- ],
- ),
- ),
- Expanded(
- child: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 10),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- // Text(
- // "Estatus: ${status.toString().split('.').last}",
- // style: const TextStyle(
- // fontWeight: FontWeight.bold,
- // color: Colors.black,
- // ),
- // ),
- ],
- ),
- // const SizedBox(height: 16),
- // IconDataByStatus(status: status),
- const SizedBox(height: 16),
- Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(10),
- border: Border.all(color: Colors.grey.shade200),
- ),
- child: Column(children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- const Text("Pedido Actual",
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 20,
- color: Colors.black,
- )),
- GestureDetector(
- onTap: () {
- Navigator.of(context)
- .pushNamed('creacion-pedido');
- },
- child: const Row(children: [
- Text("Ver detalle"),
- Icon(Icons.arrow_forward_ios_rounded),
- ]),
- )
- ]),
- const SizedBox(height: 10),
- const CustomProductCard(
- titulo: "Original Cheesse Meat burger with Chips",
- precio: "15.20",
- cantidad: 1,
- ),
- const SizedBox(height: 10),
- const CustomProductCard(
- titulo: "Original Cheesse Meat burger with Chips",
- precio: "15.20",
- cantidad: 1,
- ),
- const SizedBox(height: 10),
- const CustomProductCard(
- titulo: "Original Cheesse Meat burger with Chips",
- precio: "15.20",
- cantidad: 1,
- ),
- const SizedBox(height: 10),
- const Divider(),
- const Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- "Total",
- style: TextStyle(
- fontSize: 20, fontWeight: FontWeight.bold),
- ),
- Text(
- "\$45.60",
- style: TextStyle(
- fontSize: 20, fontWeight: FontWeight.bold),
- ),
- ],
- )
- ]),
- ),
- //? const OrdenesScreen(),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
- class TableCard extends StatelessWidget {
- final Mesa mesa;
- const TableCard({
- super.key,
- required this.mesa,
- });
- @override
- Widget build(BuildContext context) {
- final status = mesa.estado ?? EstadoPedido.disponible;
- final mesaViewModel = Provider.of<MesaViewModel>(context, listen: true);
- final style = getStatusStyle(status);
- return Card(
- borderOnForeground: false,
- color: style.cardColor,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- IconButton(
- onPressed: () {
- mesaViewModel.cambiarEstadoPedidoMesa(style.nextStatus);
- print('Cambiando estado de la mesa ${style.nextStatus}');
- },
- iconSize: 48,
- style: ButtonStyle(
- backgroundColor: MaterialStateProperty.all(style.backgroundColor),
- ),
- icon: Icon(style.icon, color: style.iconColor),
- ),
- const SizedBox(height: 8),
- Text(
- mesa.nombre ?? 'Mesa sin nombre',
- style: TextStyle(
- color: status == EstadoPedido.disponible
- ? Colors.black
- : Colors.black87,
- fontSize: 20,
- fontWeight: FontWeight.w500,
- ),
- ),
- Container(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
- decoration: BoxDecoration(
- color: style.backgroundColor,
- borderRadius: BorderRadius.circular(20),
- ),
- child: Text(
- status.toString().split('.').last,
- style: TextStyle(
- color: style.iconColor,
- fontWeight: FontWeight.bold,
- ),
- ),
- )
- ],
- ),
- );
- }
- }
|