123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- // ignore_for_file: use_build_context_synchronously
- import 'package:flutter/material.dart';
- import 'package:yoshi_papas_app/widgets/widgets.dart';
- import 'package:provider/provider.dart';
- import 'package:intl/intl.dart';
- import '../../viewmodels/viewmodels.dart';
- import '../../models/models.dart';
- import '../../themes/themes.dart';
- import 'pedido_form.dart';
- import '../../services/services.dart' as servicio;
- class PedidoScreen extends StatefulWidget {
- const PedidoScreen({Key? key}) : super(key: key);
- @override
- State<PedidoScreen> createState() => Formulario();
- }
- class Formulario extends State<PedidoScreen> {
- final _busqueda = TextEditingController(text: '');
- ScrollController horizontalScrollController = ScrollController();
- DateTime? fechaInicio = DateTime.now();
- DateTime? fechaFin;
- Size? _size;
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
- // await Provider.of<PedidoViewModel>(context, listen: false)
- // .setIsLoading(true);
- // await Provider.of<PedidoViewModel>(context, listen: false)
- // .fetchRegistros();
- // List<Empresa> lasempresas =
- // Provider.of<EmpresaViewModel>(context, listen: false).empresas;
- // if (lasempresas.isNotEmpty) {
- // setState(() {
- // empresa = lasempresas.first;
- // });
- // }
- // await Future.delayed(const Duration(seconds: 1));
- // await Provider.of<OrdenesViewModel>(context, listen: false)
- // .setIsLoading(false);
- });
- }
- @override
- void dispose() {
- horizontalScrollController.dispose();
- super.dispose();
- }
- // go(Orden item) async {
- // Provider.of<CamaraViewModel>(context, listen: false).limpiarFotos();
- // Provider.of<MediaViewModel>(context, listen: false).limpiar();
- // Provider.of<OrdenesViewModel>(context, listen: false).selectOrden(item);
- // Navigator.push(
- // context,
- // MaterialPageRoute(
- // builder: (context) => const OrdenForm(),
- // ),
- // ).then((value) async {
- // await Provider.of<OrdenesViewModel>(context, listen: false)
- // .fetchRegistros();
- // });
- // }
- @override
- Widget build(BuildContext context) {
- //final mvm = Provider.of<PedidoViewModel>(context);
- double screenWidth = MediaQuery.of(context).size.width;
- final isMobile = screenWidth < 1250;
- final double? columnSpacing = isMobile ? null : 0;
- //final isLoading = mvm.isLoading;
- // if (isLoading) return const Cargando();
- TextStyle estilo = const TextStyle(fontWeight: FontWeight.bold);
- List<DataRow> registros = [];
- //if (mvm.registros.isNotEmpty) {
- var vuelta = 0;
- //for (Orden item in mvm.registros) {
- var _tipo = vuelta % 2;
- vuelta++;
- String fsalida = "";
- // if (item.fechaSalida != null) {
- // fsalida = DateFormat("dd/MM/yyyy HH:mm")
- // .format(item.fechaSalida!)
- // .toString();
- // }
- registros.add(DataRow(selected: _tipo > 0, cells: [
- DataCell(
- Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
- PopupMenuButton(
- surfaceTintColor: AppTheme.primary,
- itemBuilder: (context) => [
- PopupMenuItem(
- child: const Text('Editar'),
- onTap: () => {} /*go(item)*/,
- ),
- PopupMenuItem(
- child: const Text(
- 'Eliminar',
- ),
- onTap: () async {
- return showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: const Text("Eliminar registro"),
- content: const Text('¿Desea eliminar el registro?'),
- actions: [
- Row(children: [
- Expanded(
- child: TextButton(
- onPressed: () {
- Navigator.pop(context);
- },
- child: const Text('Cancelar'),
- )),
- Expanded(
- child: TextButton(
- onPressed: () async {
- // //await mvm.eliminar(item);
- // await mvm.fetchRegistros();
- // if (context.mounted) {
- // Navigator.pop(context);
- // }
- },
- child: const Text('Continuar'),
- ))
- ])
- ],
- );
- },
- );
- },
- ),
- PopupMenuItem(
- child: const Text('Imprimir'),
- //onTap: () => imprimir(item),
- ),
- ],
- icon: const Icon(Icons.more_vert),
- shape:
- RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
- ),
- ])),
- DataCell(
- Text('Pedido'),
- //Text(item.folio.toString()),
- // onTap: () => go(item),
- ),
- DataCell(
- Text('Petición'),
- //Text(item.numeroUnidad.toString()),
- //onTap: () => go(item),
- ),
- DataCell(
- Text('Cliente'),
- //Text(item.nombreChofer.toString()),
- //onTap: () => go(item),
- ),
- DataCell(
- Text('Mesa'),
- //Text("${item.categoriaFalla.toString()}: ${item.falla.toString()}"),
- // onTap: () => go(item),
- ),
- DataCell(
- Text('Productos Terminados'),
- //Text(item.estatus.toString()),
- //onTap: () => go(item),
- ),
- DataCell(
- Text('Visto'),
- //Text(item.estatus.toString()),
- //onTap: () => go(item),
- ),
- ]));
- //}
- //}
- _size = MediaQuery.of(context).size;
- return Scaffold(
- appBar: encabezado(
- titulo: "PEDIDOS",
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () async {
- // Aquí asumo que quieres navegar a una nueva página cuando se presione el botón
- await Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => PedidoForm(),
- ),
- );
- },
- child: const Icon(Icons
- .add), // Este es el hijo del FloatingActionButton, que define el ícono que se muestra en el botón.
- ),
- body: Column(
- children: [
- Expanded(
- child: ListView(
- padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
- children: [
- const SizedBox(height: 8),
- tarjeta(
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: LayoutBuilder(
- builder: (context, constraints) {
- if (screenWidth > 1000) {
- return Row(
- children: [
- Expanded(
- flex: 10,
- child: Row(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- BusquedaTextField(),
- ],
- )),
- SizedBox(width: 5),
- BotonBuscar()
- ],
- );
- } else {
- return Column(
- children: [
- Row(
- children: [BusquedaTextField()],
- ),
- SizedBox(height: 10),
- SizedBox(height: 15),
- Row(
- children: [BotonBuscar()],
- ),
- ],
- );
- }
- },
- ),
- ),
- ),
- const SizedBox(height: 8),
- // isLoading
- // ? const Center(child: CircularProgressIndicator())
- // : Container(),
- tarjeta(
- Column(
- children: [
- LayoutBuilder(builder: (context, constraints) {
- return SingleChildScrollView(
- scrollDirection: Axis.vertical,
- child: Scrollbar(
- controller: horizontalScrollController,
- interactive: true,
- thumbVisibility: true,
- thickness:
- 10.0, // Esto es opcional para cambiar el grosor
- child: SingleChildScrollView(
- controller: horizontalScrollController,
- scrollDirection: Axis.horizontal,
- child: ConstrainedBox(
- constraints: BoxConstraints(
- minWidth: isMobile
- ? constraints.maxWidth
- : screenWidth),
- child: DataTable(
- columnSpacing: columnSpacing,
- sortAscending: true,
- sortColumnIndex: 1,
- columns: [
- DataColumn(label: Text(" ", style: estilo)),
- DataColumn(
- label: Text("PEDIDO", style: estilo)),
- DataColumn(
- label: Text("PETICIÓN", style: estilo)),
- DataColumn(
- label: Text("CLIENTE", style: estilo)),
- DataColumn(
- label: Text("MESA", style: estilo)),
- DataColumn(
- label: Text("PRODUCTOS TERMINADOS",
- style: estilo)),
- DataColumn(
- label: Text("VISTO", style: estilo)),
- ],
- rows: registros,
- ),
- ),
- ),
- ),
- );
- }),
- // PaginationButtons(
- // currentPage: mvm.pagina,
- // totalPages: mvm.totalPaginas,
- // onPageChanged: (i) => mvm.cambiarPagina(i,
- // empresa: _selectedEmpresa, falla: _selectedFalla),
- // )
- ],
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget BusquedaTextField() {
- return Expanded(
- flex: 4,
- child: AppTextField(
- prefixIcon: const Icon(Icons.search),
- etiqueta: 'Búsqueda por folio...',
- controller: _busqueda,
- hintText: 'Búsqueda por folio...',
- ),
- );
- }
- Widget BotonBuscar() {
- return Expanded(
- flex: 2,
- child: botonElevated(
- accion: () async {
- _busqueda.text = _busqueda.text.trim();
- /* if (_busqueda.text.isEmpty && _selectedFalla == null) {
- return alerta(context);
- } */
- // OrdenesViewModel mvm =
- // Provider.of<OrdenesViewModel>(context, listen: false);
- // await mvm.setIsLoading(true);
- // await mvm.setBusqueda(_busqueda.text);
- // await mvm.fetchRegistros(
- // falla: _selectedFalla, empresa: _selectedEmpresa);
- // await mvm.setBusqueda("");
- // await mvm.setIsLoading(false);
- },
- ),
- );
- }
- }
|