pedido_form.dart 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:intl/intl.dart';
  7. import 'package:provider/provider.dart';
  8. import 'package:yoshi_papas_app/data/session/session_storage.dart';
  9. import 'package:yoshi_papas_app/views/pedido/pedido_ticket.dart';
  10. import '../../themes/themes.dart';
  11. import '../../models/models.dart';
  12. import '../../viewmodels/viewmodels.dart';
  13. import 'package:collection/collection.dart';
  14. import '../../widgets/widgets.dart';
  15. class PedidoForm extends StatefulWidget {
  16. @override
  17. _PedidoFormState createState() => _PedidoFormState();
  18. }
  19. class _PedidoFormState extends State<PedidoForm> {
  20. final _busqueda = TextEditingController(text: '');
  21. final TextEditingController _descuentoController = TextEditingController();
  22. CategoriaProductoViewModel cvm = CategoriaProductoViewModel();
  23. ProductoViewModel pvm = ProductoViewModel();
  24. PedidoViewModel pedvm = PedidoViewModel();
  25. bool _isLoading = false;
  26. CategoriaProducto? categoriaSeleccionada;
  27. List<CategoriaProducto> categorias = [];
  28. List<Producto> productos = [];
  29. List<ItemCarrito> carrito = [];
  30. Producto? _productoActual;
  31. bool _estadoBusqueda = false;
  32. Pedido? pedidoActual;
  33. ScrollController _gridViewController = ScrollController();
  34. ScrollController _categoryScrollController = ScrollController();
  35. final _searchController = TextEditingController();
  36. final NumberFormat _numberFormat = NumberFormat.decimalPattern('es_MX');
  37. int? selectedDescuento = 0;
  38. double subtotal = 0;
  39. double precioDescuento = 0;
  40. double totalPedido = 0;
  41. bool efectivoSeleccionado = false;
  42. bool tarjetaSeleccionada = false;
  43. bool transferenciaSeleccionada = false;
  44. TextEditingController efectivoController = TextEditingController();
  45. TextEditingController tarjetaController = TextEditingController();
  46. TextEditingController transferenciaController = TextEditingController();
  47. double cambio = 0.0;
  48. double calcularTotalPedido() {
  49. double total = 0;
  50. for (var item in carrito) {
  51. total += item.producto.precio! * item.cantidad;
  52. item.selectedToppings.forEach((categoryId, selectedToppingIds) {
  53. for (int toppingId in selectedToppingIds) {
  54. Producto? topping = item.selectableToppings[categoryId]?.firstWhere(
  55. (topping) => topping.id == toppingId,
  56. orElse: () => Producto(precio: 0));
  57. if (topping != null) {
  58. total += (topping.precio ?? 0.0) * item.cantidad;
  59. }
  60. }
  61. });
  62. }
  63. return total;
  64. }
  65. double aplicarDescuento(double total, int? descuento) {
  66. if (descuento != null && descuento > 0) {
  67. double totalPedido = total * (1 - descuento / 100);
  68. // print(
  69. // 'Total con descuento: $totalPedido (Descuento aplicado: $descuento%)');
  70. return totalPedido;
  71. }
  72. // print('Sin descuento, total: $total');
  73. return total;
  74. }
  75. @override
  76. void initState() {
  77. super.initState();
  78. cargarCategoriasIniciales().then((_) {
  79. if (categorias.isNotEmpty) {
  80. categoriaSeleccionada = categorias.first;
  81. cargarProductosPorCategoria(categoriaSeleccionada!.id);
  82. }
  83. });
  84. Provider.of<DescuentoViewModel>(context, listen: false).cargarDescuentos();
  85. }
  86. void _onSearchChanged(String value) async {
  87. if (value.isEmpty) {
  88. cargarProductosPorCategoria(
  89. categoriaSeleccionada?.id ?? categorias.first.id);
  90. } else {
  91. setState(() {
  92. _estadoBusqueda = true;
  93. });
  94. await Provider.of<ProductoViewModel>(context, listen: false)
  95. .fetchLocalByName(nombre: value);
  96. setState(() {
  97. productos =
  98. Provider.of<ProductoViewModel>(context, listen: false).productos;
  99. });
  100. }
  101. }
  102. void _recalcularTotal() {
  103. subtotal = calcularTotalPedido();
  104. // print('Subtotal: $subtotal');
  105. // print('Descuento seleccionado: $selectedDescuento%');
  106. precioDescuento = subtotal * (selectedDescuento! / 100);
  107. totalPedido = subtotal - precioDescuento;
  108. setState(() {
  109. pedidoActual = pedidoActual ?? Pedido();
  110. pedidoActual!.totalPedido = totalPedido;
  111. pedidoActual!.descuento = selectedDescuento;
  112. });
  113. // print('Precio descuento: $precioDescuento');
  114. // print('Total con descuento aplicado: $totalPedido');
  115. }
  116. bool validarMinimosSeleccionados() {
  117. for (var item in carrito) {
  118. for (var categoriaId in item.selectableToppings.keys) {
  119. final categoria = categorias.firstWhere((c) => c.id == categoriaId);
  120. final minimoRequerido = categoria.minimo ?? 0;
  121. final seleccionados = item.selectedToppings[categoriaId]?.length ?? 0;
  122. if (minimoRequerido > 0 && seleccionados < minimoRequerido) {
  123. showDialog(
  124. context: context,
  125. builder: (BuildContext context) {
  126. return AlertDialog(
  127. title: const Text('Faltan Toppings',
  128. style:
  129. TextStyle(fontWeight: FontWeight.w500, fontSize: 22)),
  130. content: Text(
  131. 'El producto ${item.producto.nombre} requiere que seleccione al menos $minimoRequerido topping en la categoría ${categoria.nombre}.',
  132. style: TextStyle(fontSize: 18)),
  133. actions: <Widget>[
  134. TextButton(
  135. onPressed: () => Navigator.of(context).pop(),
  136. child: const Text('Aceptar'),
  137. style: ButtonStyle(
  138. padding: MaterialStatePropertyAll(
  139. EdgeInsets.fromLTRB(20, 10, 20, 10)),
  140. backgroundColor:
  141. MaterialStatePropertyAll(AppTheme.tertiary),
  142. foregroundColor:
  143. MaterialStatePropertyAll(AppTheme.quaternary))),
  144. ],
  145. );
  146. },
  147. );
  148. return false;
  149. }
  150. }
  151. }
  152. return true;
  153. }
  154. void _finalizeOrder() async {
  155. if (carrito.isEmpty) {
  156. showDialog(
  157. context: context,
  158. builder: (BuildContext context) {
  159. return AlertDialog(
  160. title: const Text('Pedido vacío',
  161. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22)),
  162. content: const Text(
  163. 'No puedes finalizar un pedido sin productos. Por favor, agrega al menos un producto.',
  164. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18)),
  165. shape:
  166. RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
  167. actions: <Widget>[
  168. TextButton(
  169. style: TextButton.styleFrom(
  170. padding: EdgeInsets.fromLTRB(30, 20, 30, 20),
  171. foregroundColor: AppTheme.quaternary,
  172. backgroundColor: AppTheme.tertiary),
  173. onPressed: () {
  174. Navigator.of(context).pop();
  175. },
  176. child: const Text('Aceptar', style: TextStyle(fontSize: 18)),
  177. ),
  178. ],
  179. );
  180. },
  181. );
  182. return;
  183. }
  184. if (!validarMinimosSeleccionados()) {
  185. return;
  186. }
  187. await _promptForCustomerName();
  188. }
  189. Future<void> _promptForCustomerName() async {
  190. TextEditingController nombreController = TextEditingController();
  191. TextEditingController comentarioController = TextEditingController();
  192. String errorMessage = '';
  193. double faltante = totalPedido;
  194. bool totalCompletado = false;
  195. bool efectivoCompleto = false;
  196. bool tarjetaCompleto = false;
  197. bool transferenciaCompleto = false;
  198. void _calcularCambio(StateSetter setState) {
  199. double totalPagado = (double.tryParse(efectivoController.text) ?? 0) +
  200. (double.tryParse(tarjetaController.text) ?? 0) +
  201. (double.tryParse(transferenciaController.text) ?? 0);
  202. setState(() {
  203. cambio = totalPagado - totalPedido;
  204. if (cambio < 0) {
  205. faltante = totalPedido - totalPagado;
  206. cambio = 0;
  207. totalCompletado = false;
  208. } else {
  209. faltante = 0;
  210. totalCompletado = true;
  211. }
  212. // Si el total ha sido alcanzado o excedido, desactivar otros métodos de pago
  213. if (totalPagado >= totalPedido) {
  214. if (!efectivoSeleccionado) efectivoSeleccionado = false;
  215. if (!tarjetaSeleccionada) tarjetaSeleccionada = false;
  216. if (!transferenciaSeleccionada) transferenciaSeleccionada = false;
  217. }
  218. });
  219. }
  220. void _validarCantidad(
  221. StateSetter setState, TextEditingController controller) {
  222. double cantidad = double.tryParse(controller.text) ?? 0;
  223. if (cantidad > totalPedido) {
  224. setState(() {
  225. controller.text = totalPedido.toStringAsFixed(2);
  226. });
  227. }
  228. _calcularCambio(setState);
  229. }
  230. bool _isPaymentOptionEnabled(bool isSelected) {
  231. return !totalCompletado || isSelected;
  232. }
  233. bool? shouldSave = await showDialog<bool>(
  234. context: context,
  235. builder: (BuildContext context) {
  236. return StatefulBuilder(
  237. builder: (context, setState) {
  238. return RawKeyboardListener(
  239. focusNode: FocusNode(),
  240. onKey: (RawKeyEvent event) {
  241. if (event.isKeyPressed(LogicalKeyboardKey.enter) &&
  242. totalCompletado) {
  243. Navigator.of(context).pop(true);
  244. }
  245. },
  246. child: AlertDialog(
  247. actionsPadding: EdgeInsets.fromLTRB(50, 10, 50, 30),
  248. title: const Text(
  249. 'Finalizar Pedido',
  250. style: TextStyle(fontSize: 22, fontWeight: FontWeight.w500),
  251. ),
  252. content: Container(
  253. height: 600,
  254. child: Column(
  255. children: [
  256. Expanded(
  257. child: SingleChildScrollView(
  258. child: Column(
  259. children: [
  260. AppTextField(
  261. controller: nombreController,
  262. etiqueta: 'Nombre',
  263. hintText: "Nombre del Cliente",
  264. ),
  265. const SizedBox(height: 10),
  266. AppTextField(
  267. controller: comentarioController,
  268. etiqueta: 'Comentarios (opcional)',
  269. hintText: 'Comentarios',
  270. maxLines: 2,
  271. ),
  272. const SizedBox(height: 10),
  273. Align(
  274. alignment: Alignment.center,
  275. child: Text(
  276. 'Métodos de pago',
  277. style: TextStyle(
  278. fontWeight: FontWeight.bold,
  279. fontSize: 20),
  280. ),
  281. ),
  282. const SizedBox(height: 10),
  283. // Efectivo
  284. GestureDetector(
  285. onTap: () {
  286. if (_isPaymentOptionEnabled(
  287. efectivoSeleccionado)) {
  288. setState(() {
  289. efectivoSeleccionado =
  290. !efectivoSeleccionado;
  291. if (!efectivoSeleccionado) {
  292. efectivoCompleto = false;
  293. efectivoController.clear();
  294. _calcularCambio(setState);
  295. } else if (efectivoCompleto) {
  296. efectivoController.text =
  297. totalPedido.toStringAsFixed(2);
  298. _calcularCambio(setState);
  299. }
  300. });
  301. }
  302. },
  303. child: Row(
  304. mainAxisAlignment:
  305. MainAxisAlignment.spaceBetween,
  306. crossAxisAlignment:
  307. CrossAxisAlignment.center,
  308. children: [
  309. Row(
  310. children: [
  311. Checkbox(
  312. activeColor: AppTheme.primary,
  313. value: efectivoSeleccionado,
  314. onChanged: _isPaymentOptionEnabled(
  315. efectivoSeleccionado)
  316. ? (bool? value) {
  317. setState(() {
  318. efectivoSeleccionado =
  319. value ?? false;
  320. if (!efectivoSeleccionado) {
  321. efectivoCompleto =
  322. false;
  323. efectivoController
  324. .clear();
  325. _calcularCambio(
  326. setState);
  327. } else if (efectivoCompleto) {
  328. efectivoController
  329. .text =
  330. totalPedido
  331. .toStringAsFixed(
  332. 2);
  333. _calcularCambio(
  334. setState);
  335. }
  336. });
  337. }
  338. : null,
  339. ),
  340. const Text(
  341. "Efectivo",
  342. style: TextStyle(
  343. fontSize: 18,
  344. fontWeight: FontWeight.bold),
  345. ),
  346. ],
  347. ),
  348. if (efectivoSeleccionado)
  349. SizedBox(
  350. width: 180,
  351. child: Row(
  352. crossAxisAlignment:
  353. CrossAxisAlignment.start,
  354. children: [
  355. Column(
  356. children: [
  357. const Text('Exacto',
  358. style: TextStyle(
  359. fontSize: 18,
  360. fontWeight:
  361. FontWeight.bold,
  362. color: Colors.black)),
  363. const SizedBox(
  364. height: 17,
  365. ),
  366. Checkbox(
  367. activeColor:
  368. AppTheme.primary,
  369. value: efectivoCompleto,
  370. onChanged:
  371. efectivoSeleccionado
  372. ? (bool? value) {
  373. setState(() {
  374. efectivoCompleto =
  375. value ??
  376. false;
  377. if (efectivoCompleto) {
  378. efectivoController
  379. .text =
  380. totalPedido
  381. .toStringAsFixed(2);
  382. _calcularCambio(
  383. setState);
  384. } else {
  385. efectivoController
  386. .clear();
  387. _calcularCambio(
  388. setState);
  389. }
  390. });
  391. }
  392. : null,
  393. ),
  394. ],
  395. ),
  396. const SizedBox(
  397. width: 5,
  398. ),
  399. Expanded(
  400. child: AppTextField(
  401. controller:
  402. efectivoController,
  403. etiqueta: 'Cantidad',
  404. hintText: '0.00',
  405. keyboardType:
  406. TextInputType.number,
  407. onChanged: (value) =>
  408. _calcularCambio(setState),
  409. ),
  410. ),
  411. ],
  412. ),
  413. ),
  414. ],
  415. ),
  416. ),
  417. const SizedBox(height: 10),
  418. // Tarjeta
  419. GestureDetector(
  420. onTap: () {
  421. if (_isPaymentOptionEnabled(
  422. tarjetaSeleccionada)) {
  423. setState(() {
  424. tarjetaSeleccionada =
  425. !tarjetaSeleccionada;
  426. if (!tarjetaSeleccionada) {
  427. tarjetaController.clear();
  428. _calcularCambio(setState);
  429. }
  430. });
  431. }
  432. },
  433. child: Row(
  434. mainAxisAlignment:
  435. MainAxisAlignment.spaceBetween,
  436. crossAxisAlignment:
  437. CrossAxisAlignment.center,
  438. children: [
  439. Row(
  440. children: [
  441. Checkbox(
  442. activeColor: AppTheme.primary,
  443. value: tarjetaSeleccionada,
  444. onChanged: _isPaymentOptionEnabled(
  445. tarjetaSeleccionada)
  446. ? (bool? value) {
  447. setState(() {
  448. tarjetaSeleccionada =
  449. value ?? false;
  450. if (!tarjetaSeleccionada) {
  451. tarjetaController
  452. .clear();
  453. _calcularCambio(
  454. setState);
  455. }
  456. });
  457. }
  458. : null,
  459. ),
  460. const Text(
  461. "Tarjeta",
  462. style: TextStyle(
  463. fontSize: 18,
  464. fontWeight: FontWeight.bold),
  465. ),
  466. ],
  467. ),
  468. if (tarjetaSeleccionada)
  469. SizedBox(
  470. width: 180,
  471. child: Row(
  472. crossAxisAlignment:
  473. CrossAxisAlignment.start,
  474. children: [
  475. Column(
  476. children: [
  477. const Text('Exacto',
  478. style: TextStyle(
  479. fontSize: 18,
  480. fontWeight:
  481. FontWeight.bold,
  482. color: Colors.black)),
  483. const SizedBox(
  484. height: 17,
  485. ),
  486. Checkbox(
  487. activeColor:
  488. AppTheme.primary,
  489. value: tarjetaCompleto,
  490. onChanged:
  491. tarjetaSeleccionada
  492. ? (bool? value) {
  493. setState(() {
  494. tarjetaCompleto =
  495. value ??
  496. false;
  497. if (tarjetaCompleto) {
  498. tarjetaController
  499. .text =
  500. totalPedido
  501. .toStringAsFixed(2);
  502. _calcularCambio(
  503. setState);
  504. } else {
  505. tarjetaController
  506. .clear();
  507. _calcularCambio(
  508. setState);
  509. }
  510. });
  511. }
  512. : null,
  513. ),
  514. ],
  515. ),
  516. const SizedBox(
  517. width: 5,
  518. ),
  519. Expanded(
  520. child: AppTextField(
  521. controller: tarjetaController,
  522. etiqueta: 'Cantidad',
  523. hintText: '0.00',
  524. keyboardType:
  525. TextInputType.number,
  526. onChanged: (value) {
  527. _validarCantidad(setState,
  528. tarjetaController);
  529. },
  530. ),
  531. ),
  532. ],
  533. ),
  534. ),
  535. ],
  536. ),
  537. ),
  538. const SizedBox(height: 10),
  539. // Transferencia
  540. GestureDetector(
  541. onTap: () {
  542. if (_isPaymentOptionEnabled(
  543. transferenciaSeleccionada)) {
  544. setState(() {
  545. transferenciaSeleccionada =
  546. !transferenciaSeleccionada;
  547. if (!transferenciaSeleccionada) {
  548. transferenciaController.clear();
  549. _calcularCambio(setState);
  550. }
  551. });
  552. }
  553. },
  554. child: Row(
  555. mainAxisAlignment:
  556. MainAxisAlignment.spaceBetween,
  557. crossAxisAlignment:
  558. CrossAxisAlignment.center,
  559. children: [
  560. Row(
  561. children: [
  562. Checkbox(
  563. activeColor: AppTheme.primary,
  564. value: transferenciaSeleccionada,
  565. onChanged: _isPaymentOptionEnabled(
  566. transferenciaSeleccionada)
  567. ? (bool? value) {
  568. setState(() {
  569. transferenciaSeleccionada =
  570. value ?? false;
  571. if (!transferenciaSeleccionada) {
  572. transferenciaController
  573. .clear();
  574. _calcularCambio(
  575. setState);
  576. }
  577. });
  578. }
  579. : null,
  580. ),
  581. const Text(
  582. "Transferencia",
  583. style: TextStyle(
  584. fontSize: 18,
  585. fontWeight: FontWeight.bold),
  586. ),
  587. ],
  588. ),
  589. if (transferenciaSeleccionada)
  590. SizedBox(
  591. width: 180,
  592. child: Row(
  593. crossAxisAlignment:
  594. CrossAxisAlignment.start,
  595. children: [
  596. Column(
  597. children: [
  598. const Text('Exacto',
  599. style: TextStyle(
  600. fontSize: 18,
  601. fontWeight:
  602. FontWeight.bold,
  603. color: Colors.black)),
  604. const SizedBox(
  605. height: 17,
  606. ),
  607. Checkbox(
  608. activeColor:
  609. AppTheme.primary,
  610. value:
  611. transferenciaCompleto,
  612. onChanged:
  613. transferenciaSeleccionada
  614. ? (bool? value) {
  615. setState(() {
  616. transferenciaCompleto =
  617. value ??
  618. false;
  619. if (transferenciaCompleto) {
  620. transferenciaController
  621. .text =
  622. totalPedido
  623. .toStringAsFixed(2);
  624. _calcularCambio(
  625. setState);
  626. } else {
  627. transferenciaController
  628. .clear();
  629. _calcularCambio(
  630. setState);
  631. }
  632. });
  633. }
  634. : null,
  635. ),
  636. ],
  637. ),
  638. const SizedBox(
  639. width: 5,
  640. ),
  641. Expanded(
  642. child: AppTextField(
  643. controller:
  644. transferenciaController,
  645. etiqueta: 'Cantidad',
  646. hintText: '0.00',
  647. keyboardType:
  648. TextInputType.number,
  649. onChanged: (value) {
  650. _validarCantidad(setState,
  651. transferenciaController);
  652. },
  653. ),
  654. ),
  655. ],
  656. ),
  657. ),
  658. ],
  659. ),
  660. ),
  661. const SizedBox(height: 10),
  662. // Mostrar el total del pedido y la cantidad faltante
  663. Align(
  664. alignment: Alignment.centerRight,
  665. child: Column(
  666. crossAxisAlignment:
  667. CrossAxisAlignment.end,
  668. children: [
  669. Text(
  670. 'Total del pedido: \$${totalPedido.toStringAsFixed(2)}',
  671. style: const TextStyle(
  672. fontWeight: FontWeight.bold,
  673. fontSize: 18),
  674. ),
  675. if (faltante > 0)
  676. Text(
  677. 'Faltante: \$${faltante.toStringAsFixed(2)}',
  678. style: const TextStyle(
  679. color: Colors.red,
  680. fontSize: 18,
  681. fontWeight: FontWeight.bold),
  682. )
  683. else if (cambio > 0)
  684. Text(
  685. 'Cambio: \$${cambio.toStringAsFixed(2)}',
  686. style: const TextStyle(
  687. color: Colors.green,
  688. fontSize: 18,
  689. fontWeight: FontWeight.bold)),
  690. ]),
  691. ),
  692. ],
  693. ),
  694. ),
  695. ),
  696. // Aquí mantenemos los botones fijos
  697. Row(
  698. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  699. children: [
  700. TextButton(
  701. child: const Text('Cancelar',
  702. style: TextStyle(fontSize: 18)),
  703. onPressed: () {
  704. Navigator.of(context).pop(false);
  705. },
  706. style: ButtonStyle(
  707. padding: MaterialStatePropertyAll(
  708. EdgeInsets.fromLTRB(30, 20, 30, 20)),
  709. backgroundColor:
  710. MaterialStatePropertyAll(Colors.red),
  711. foregroundColor: MaterialStatePropertyAll(
  712. AppTheme.secondary)),
  713. ),
  714. const SizedBox(width: 100),
  715. TextButton(
  716. child: const Text('Guardar',
  717. style: TextStyle(fontSize: 18)),
  718. onPressed: totalCompletado
  719. ? () {
  720. Navigator.of(context).pop(true);
  721. }
  722. : null,
  723. style: ButtonStyle(
  724. padding: MaterialStatePropertyAll(
  725. EdgeInsets.fromLTRB(30, 20, 30, 20)),
  726. backgroundColor: MaterialStatePropertyAll(
  727. totalCompletado
  728. ? AppTheme.tertiary
  729. : Colors.grey),
  730. foregroundColor: MaterialStatePropertyAll(
  731. AppTheme.quaternary)),
  732. ),
  733. ],
  734. ),
  735. ],
  736. ),
  737. ),
  738. ));
  739. },
  740. );
  741. },
  742. );
  743. if (shouldSave ?? false) {
  744. prepararPedidoActual(nombreController.text, comentarioController.text);
  745. }
  746. }
  747. void prepararPedidoActual(String nombreCliente, String comentarios) async {
  748. String now = DateTime.now().toUtc().toIso8601String();
  749. int? idUsuario = await SessionStorage().getId();
  750. Pedido nuevoPedido = Pedido(
  751. peticion: now,
  752. nombreCliente: nombreCliente,
  753. comentarios: comentarios,
  754. estatus: "TERMINADO",
  755. totalPedido: totalPedido,
  756. descuento: pedidoActual?.descuento,
  757. idUsuario: idUsuario,
  758. tipoPago: _obtenerTipoPago(),
  759. cantEfectivo:
  760. efectivoSeleccionado ? double.tryParse(efectivoController.text) : 0,
  761. cantTarjeta:
  762. tarjetaSeleccionada ? double.tryParse(tarjetaController.text) : 0,
  763. cantTransferencia: transferenciaSeleccionada
  764. ? double.tryParse(transferenciaController.text)
  765. : 0,
  766. );
  767. List<PedidoProducto> listaPedidoProducto = carrito.map((item) {
  768. List<PedidoProductoTopping> selectedToppings = [];
  769. item.selectedToppings.forEach((categoryId, selectedToppingIds) {
  770. for (int toppingId in selectedToppingIds) {
  771. selectedToppings.add(PedidoProductoTopping(
  772. idCategoria: categoryId,
  773. idTopping: toppingId,
  774. ));
  775. }
  776. });
  777. return PedidoProducto(
  778. idProducto: item.producto.id,
  779. producto: item.producto,
  780. costoUnitario: item.producto.precio.toString(),
  781. cantidad: item.cantidad,
  782. comentario: comentarios,
  783. toppings: selectedToppings,
  784. );
  785. }).toList();
  786. nuevoPedido.productos = listaPedidoProducto;
  787. bool result = await Provider.of<PedidoViewModel>(context, listen: false)
  788. .guardarPedidoLocal(pedido: nuevoPedido);
  789. if (!mounted) return;
  790. if (result) {
  791. Pedido? pedidoCompleto =
  792. await Provider.of<PedidoViewModel>(context, listen: false)
  793. .fetchPedidoConProductos(nuevoPedido.id!);
  794. if (pedidoCompleto != null) {
  795. imprimirTicketsJuntos(context, pedidoCompleto);
  796. }
  797. Navigator.of(context).pop();
  798. } else {
  799. print("Error al guardar el pedido");
  800. }
  801. }
  802. String _obtenerTipoPago() {
  803. List<String> tiposPago = [];
  804. if (efectivoSeleccionado) tiposPago.add('Efectivo');
  805. if (tarjetaSeleccionada) tiposPago.add('Tarjeta');
  806. if (transferenciaSeleccionada) tiposPago.add('Transferencia');
  807. return tiposPago.join(',');
  808. }
  809. void _limpiarBusqueda() async {
  810. setState(() {
  811. _busqueda.text = '';
  812. _estadoBusqueda = false;
  813. });
  814. await cargarCategoriasIniciales();
  815. }
  816. Future<void> cargarProductosIniciales() async {
  817. setState(() => _isLoading = true);
  818. await Provider.of<ProductoViewModel>(context, listen: false)
  819. .fetchLocalAll();
  820. productos =
  821. Provider.of<ProductoViewModel>(context, listen: false).productos;
  822. setState(() => _isLoading = false);
  823. }
  824. @override
  825. void dispose() {
  826. _gridViewController.dispose();
  827. _searchController.dispose();
  828. _categoryScrollController.dispose();
  829. super.dispose();
  830. }
  831. Future<void> cargarCategoriasIniciales() async {
  832. setState(() => _isLoading = true);
  833. await Provider.of<CategoriaProductoViewModel>(context, listen: false)
  834. .fetchLocalAll();
  835. categorias = Provider.of<CategoriaProductoViewModel>(context, listen: false)
  836. .categoriaProductos;
  837. if (categorias.isNotEmpty) {
  838. categoriaSeleccionada = categorias.first;
  839. cargarProductosPorCategoria(categoriaSeleccionada!.id);
  840. }
  841. setState(() => _isLoading = false);
  842. if (categorias.isNotEmpty) {
  843. categoriaSeleccionada = categorias.first;
  844. }
  845. }
  846. void cargarProductosPorCategoria(int categoriaId) async {
  847. setState(() => _isLoading = true);
  848. await Provider.of<ProductoViewModel>(context, listen: false)
  849. .fetchAllByCategory(categoriaId);
  850. productos =
  851. Provider.of<ProductoViewModel>(context, listen: false).productos;
  852. setState(() => _isLoading = false);
  853. }
  854. void agregarAlCarrito(Producto producto) async {
  855. var existente = carrito.firstWhereOrNull((item) =>
  856. item.producto.id == producto.id &&
  857. mapEquals(item.selectedToppings, {}));
  858. if (existente != null) {
  859. setState(() {
  860. existente.cantidad++;
  861. });
  862. } else {
  863. Map<int, List<Producto>> toppingsSeleccionables =
  864. await obtenerToppingsSeleccionables(producto);
  865. setState(() {
  866. carrito.add(ItemCarrito(
  867. producto: producto,
  868. cantidad: 1,
  869. selectableToppings: toppingsSeleccionables,
  870. ));
  871. });
  872. }
  873. _recalcularTotal();
  874. }
  875. Future<Map<int, List<Producto>>> obtenerToppingsSeleccionables(
  876. Producto producto) async {
  877. Map<int, List<Producto>> toppingsSeleccionables = {};
  878. final toppingCategories =
  879. await pvm.obtenerToppingsPorProducto(producto.id!);
  880. for (int toppingId in toppingCategories) {
  881. Producto? topping = await pvm.obtenerProductoPorId(toppingId);
  882. if (topping != null && topping.idCategoria != null) {
  883. toppingsSeleccionables[topping.idCategoria!] ??= [];
  884. toppingsSeleccionables[topping.idCategoria]!.add(topping);
  885. }
  886. }
  887. return toppingsSeleccionables;
  888. }
  889. void quitarDelCarrito(Producto producto) {
  890. setState(() {
  891. var indice =
  892. carrito.indexWhere((item) => item.producto.id == producto.id);
  893. if (indice != -1) {
  894. if (carrito[indice].cantidad > 1) {
  895. carrito[indice].cantidad--;
  896. } else {
  897. carrito.removeAt(indice);
  898. }
  899. }
  900. });
  901. }
  902. void addToCart(Producto producto) {
  903. var existingIndex = carrito.indexWhere((item) =>
  904. item.producto.id == producto.id &&
  905. mapEquals(item.selectedToppings, {}));
  906. if (existingIndex != -1) {
  907. setState(() {
  908. carrito[existingIndex].cantidad++;
  909. });
  910. } else {
  911. setState(() {
  912. carrito.add(ItemCarrito(producto: producto, cantidad: 1));
  913. });
  914. }
  915. }
  916. void finalizeCustomization() {
  917. if (_productoActual != null) {
  918. addToCart(_productoActual!);
  919. setState(() {
  920. _productoActual = null;
  921. });
  922. }
  923. }
  924. Widget _buildDiscountSection() {
  925. return Padding(
  926. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  927. child: Row(
  928. crossAxisAlignment: CrossAxisAlignment.center,
  929. children: [
  930. const Text(
  931. 'Descuento',
  932. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  933. ),
  934. const Spacer(),
  935. ConstrainedBox(
  936. constraints: const BoxConstraints(
  937. maxWidth: 150,
  938. ),
  939. child: Consumer<DescuentoViewModel>(
  940. builder: (context, viewModel, child) {
  941. return AppDropdownModel<int>(
  942. hint: 'Seleccionar',
  943. items: viewModel.descuentos
  944. .map(
  945. (descuento) => DropdownMenuItem<int>(
  946. value: descuento.porcentaje,
  947. child: Text(
  948. '${descuento.porcentaje}%',
  949. style: const TextStyle(color: Colors.black),
  950. ),
  951. ),
  952. )
  953. .toList(),
  954. selectedValue: selectedDescuento,
  955. onChanged: (value) {
  956. setState(() {
  957. selectedDescuento = value;
  958. _recalcularTotal();
  959. });
  960. },
  961. );
  962. },
  963. ),
  964. ),
  965. ],
  966. ),
  967. );
  968. }
  969. Widget _buildTotalSection() {
  970. String formattedsubtotal = _numberFormat.format(subtotal);
  971. String formattedPrecioDescuento = _numberFormat.format(precioDescuento);
  972. String formattedtotalPedido = _numberFormat.format(totalPedido);
  973. return Padding(
  974. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  975. child: Column(
  976. crossAxisAlignment: CrossAxisAlignment.start,
  977. children: [
  978. if (precioDescuento > 0)
  979. Column(
  980. children: [
  981. Row(
  982. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  983. children: [
  984. const Text('Subtotal',
  985. style: TextStyle(
  986. fontWeight: FontWeight.bold, fontSize: 18)),
  987. Text("\$$formattedsubtotal",
  988. style: const TextStyle(
  989. fontWeight: FontWeight.bold, fontSize: 18)),
  990. ],
  991. ),
  992. const SizedBox(height: 10),
  993. Row(
  994. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  995. children: [
  996. const Text('Descuento',
  997. style: TextStyle(
  998. fontWeight: FontWeight.bold, fontSize: 18)),
  999. Text("-\$$formattedPrecioDescuento",
  1000. style: const TextStyle(
  1001. fontWeight: FontWeight.bold, fontSize: 18)),
  1002. ],
  1003. ),
  1004. ],
  1005. ),
  1006. const SizedBox(height: 10),
  1007. Row(
  1008. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1009. children: [
  1010. const Text('Total',
  1011. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
  1012. Text("\$$formattedtotalPedido",
  1013. style: const TextStyle(
  1014. fontWeight: FontWeight.bold, fontSize: 18)),
  1015. ],
  1016. ),
  1017. ],
  1018. ),
  1019. );
  1020. }
  1021. @override
  1022. Widget build(BuildContext context) {
  1023. return Scaffold(
  1024. appBar: AppBar(
  1025. title:
  1026. Text("Crear Pedido", style: TextStyle(color: AppTheme.secondary)),
  1027. iconTheme: IconThemeData(color: AppTheme.secondary)),
  1028. body: Row(
  1029. children: [
  1030. Flexible(
  1031. flex: 3,
  1032. child: _buildCartSection(),
  1033. ),
  1034. SizedBox(width: 35),
  1035. Flexible(flex: 7, child: _buildProductsSection()),
  1036. ],
  1037. ),
  1038. );
  1039. }
  1040. Widget _buildCartSection() {
  1041. return Card(
  1042. margin: const EdgeInsets.all(8.0),
  1043. child: Column(
  1044. children: [
  1045. const Padding(
  1046. padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 16.0),
  1047. child: Row(
  1048. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1049. children: [
  1050. Text('Producto',
  1051. style:
  1052. TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
  1053. Text('Cantidad',
  1054. style:
  1055. TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
  1056. ],
  1057. ),
  1058. ),
  1059. Expanded(
  1060. child: ListView.builder(
  1061. itemCount: carrito.length,
  1062. itemBuilder: (context, index) {
  1063. final item = carrito[index];
  1064. return Column(
  1065. children: [
  1066. ListTile(
  1067. title: Text(item.producto.nombre!,
  1068. style: const TextStyle(fontWeight: FontWeight.w600)),
  1069. subtitle: Text('\$${item.producto.precio}',
  1070. style: const TextStyle(
  1071. fontWeight: FontWeight.bold,
  1072. color: Color(0xFF008000))),
  1073. trailing: Row(
  1074. mainAxisSize: MainAxisSize.min,
  1075. children: [
  1076. IconButton(
  1077. icon: const Icon(Icons.delete, color: Colors.red),
  1078. onPressed: () =>
  1079. eliminarProductoDelCarrito(index)),
  1080. IconButton(
  1081. icon: const Icon(Icons.remove),
  1082. onPressed: () => quitarProductoDelCarrito(item)),
  1083. const SizedBox(width: 5),
  1084. Text('${item.cantidad}',
  1085. style: const TextStyle(
  1086. fontWeight: FontWeight.bold, fontSize: 14)),
  1087. const SizedBox(width: 5),
  1088. IconButton(
  1089. icon: const Icon(Icons.add),
  1090. onPressed: () => incrementarProducto(item)),
  1091. ],
  1092. ),
  1093. ),
  1094. // ExpansionTile para todos los toppings
  1095. if (item.selectableToppings.isNotEmpty)
  1096. ExpansionTile(
  1097. initiallyExpanded: true,
  1098. title: const Text(
  1099. 'Toppings',
  1100. style: TextStyle(
  1101. fontWeight: FontWeight.bold, fontSize: 16),
  1102. ),
  1103. children: item.selectableToppings.entries.map((entry) {
  1104. final categoryId = entry.key;
  1105. final availableToppings = entry.value;
  1106. final categoria =
  1107. categorias.firstWhere((c) => c.id == categoryId);
  1108. return ExpansionTile(
  1109. initiallyExpanded: true,
  1110. title: Text(
  1111. '${categoria.nombre}'
  1112. ' (Hasta ${categoria.maximo ?? 0})'
  1113. ' ${(categoria.minimo ?? 0) > 0 ? " (Mínimo ${categoria.minimo})" : ""}',
  1114. style: const TextStyle(
  1115. fontWeight: FontWeight.bold,
  1116. fontSize: 16,
  1117. ),
  1118. ),
  1119. children: availableToppings.map((topping) {
  1120. bool isSelected = item
  1121. .selectedToppings[categoryId]
  1122. ?.contains(topping.id) ??
  1123. false;
  1124. return CheckboxListTile(
  1125. activeColor: AppTheme.primary,
  1126. title: Row(
  1127. mainAxisAlignment:
  1128. MainAxisAlignment.spaceBetween,
  1129. children: [
  1130. Text(topping.nombre!),
  1131. if (topping.precio != 0.0)
  1132. Text(
  1133. '+\$${topping.precio}',
  1134. style: const TextStyle(
  1135. color: Colors.black,
  1136. fontSize: 13,
  1137. ),
  1138. ),
  1139. ],
  1140. ),
  1141. value: isSelected,
  1142. onChanged: (bool? value) {
  1143. final maximoToppings = categoria.maximo ?? 0;
  1144. setState(() {
  1145. if (value == true) {
  1146. if ((item.selectedToppings[categoryId]
  1147. ?.length ??
  1148. 0) >=
  1149. maximoToppings) {
  1150. item.selectedToppings[categoryId]!
  1151. .remove(item
  1152. .selectedToppings[categoryId]!
  1153. .first);
  1154. }
  1155. item.selectedToppings[categoryId] ??=
  1156. <int>{};
  1157. item.selectedToppings[categoryId]!
  1158. .add(topping.id!);
  1159. } else {
  1160. item.selectedToppings[categoryId]
  1161. ?.remove(topping.id!);
  1162. if (item.selectedToppings[categoryId]
  1163. ?.isEmpty ??
  1164. false) {
  1165. item.selectedToppings
  1166. .remove(categoryId);
  1167. }
  1168. }
  1169. _recalcularTotal();
  1170. });
  1171. },
  1172. );
  1173. }).toList(),
  1174. );
  1175. }).toList(),
  1176. ),
  1177. const Divider(),
  1178. ],
  1179. );
  1180. },
  1181. ),
  1182. ),
  1183. _buildDiscountSection(),
  1184. const Divider(thickness: 5),
  1185. _buildTotalSection(),
  1186. const SizedBox(height: 25),
  1187. Padding(
  1188. padding: const EdgeInsets.all(8.0),
  1189. child: ElevatedButton(
  1190. onPressed: _finalizeOrder,
  1191. style: ElevatedButton.styleFrom(
  1192. backgroundColor: AppTheme.tertiary,
  1193. textStyle: const TextStyle(fontSize: 22),
  1194. fixedSize: const Size(250, 50),
  1195. ),
  1196. child: Text('Finalizar Pedido',
  1197. style: TextStyle(color: AppTheme.quaternary)),
  1198. ),
  1199. ),
  1200. ],
  1201. ),
  1202. );
  1203. }
  1204. void eliminarProductoDelCarrito(int index) {
  1205. setState(() {
  1206. carrito.removeAt(index);
  1207. });
  1208. _recalcularTotal();
  1209. }
  1210. void incrementarProducto(ItemCarrito item) {
  1211. setState(() {
  1212. item.cantidad++;
  1213. });
  1214. _recalcularTotal();
  1215. }
  1216. void quitarProductoDelCarrito(ItemCarrito item) {
  1217. setState(() {
  1218. if (item.cantidad > 1) {
  1219. item.cantidad--;
  1220. } else {
  1221. carrito.remove(item);
  1222. }
  1223. });
  1224. _recalcularTotal();
  1225. }
  1226. Widget _buildProductsSection() {
  1227. return Column(
  1228. children: [
  1229. const SizedBox(height: 5),
  1230. _buildSearchBar(),
  1231. const SizedBox(height: 10),
  1232. _buildCategoryButtons(),
  1233. const SizedBox(height: 15),
  1234. Expanded(
  1235. child: Consumer<ProductoViewModel>(builder: (context, model, child) {
  1236. productos = model.productos;
  1237. return GridView.builder(
  1238. controller: _gridViewController,
  1239. key: ValueKey<int>(categoriaSeleccionada?.id ?? 0),
  1240. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  1241. crossAxisCount: 3,
  1242. childAspectRatio: 3 / 2,
  1243. ),
  1244. itemCount: productos.length,
  1245. itemBuilder: (context, index) {
  1246. final producto = productos[index];
  1247. // Si no se está buscando, aplicar el filtro de categoría
  1248. if (!_estadoBusqueda &&
  1249. producto.idCategoria != categoriaSeleccionada?.id) {
  1250. return Container();
  1251. }
  1252. return Card(
  1253. child: InkWell(
  1254. onTap: () => agregarAlCarrito(producto),
  1255. child: Column(
  1256. mainAxisAlignment: MainAxisAlignment.center,
  1257. children: [
  1258. if (producto.imagen != null &&
  1259. File(producto.imagen!).existsSync())
  1260. Image.file(
  1261. File(producto.imagen!),
  1262. height: 120,
  1263. fit: BoxFit.cover,
  1264. )
  1265. else
  1266. const Icon(Icons.fastfood, size: 80),
  1267. const SizedBox(height: 8),
  1268. Padding(
  1269. padding: const EdgeInsets.symmetric(horizontal: 8.0),
  1270. child: Text(
  1271. producto.nombre ?? '',
  1272. style: const TextStyle(
  1273. fontSize: 16,
  1274. fontWeight: FontWeight.bold,
  1275. ),
  1276. textAlign: TextAlign.center,
  1277. ),
  1278. ),
  1279. const SizedBox(height: 8),
  1280. Text(
  1281. '\$${producto.precio}',
  1282. style: const TextStyle(
  1283. fontSize: 16,
  1284. fontWeight: FontWeight.bold,
  1285. color: Color(0xFF008000),
  1286. ),
  1287. ),
  1288. ],
  1289. ),
  1290. ),
  1291. );
  1292. },
  1293. );
  1294. }),
  1295. )
  1296. ],
  1297. );
  1298. }
  1299. Widget _buildCategoryButtons() {
  1300. List<CategoriaProducto> categoriasFiltradas =
  1301. categorias.where((categoria) => categoria.esToping == 0).toList();
  1302. return Container(
  1303. height: 50,
  1304. child: Scrollbar(
  1305. thumbVisibility: true,
  1306. trackVisibility: true,
  1307. interactive: true,
  1308. controller: _categoryScrollController,
  1309. child: ListView.builder(
  1310. controller: _categoryScrollController,
  1311. scrollDirection: Axis.horizontal,
  1312. itemCount: categoriasFiltradas.length,
  1313. itemBuilder: (context, index) {
  1314. final categoria = categoriasFiltradas[index];
  1315. bool isSelected = categoriaSeleccionada?.id == categoria.id;
  1316. return Padding(
  1317. padding: const EdgeInsets.symmetric(horizontal: 4.0),
  1318. child: ElevatedButton(
  1319. onPressed: () {
  1320. cargarProductosPorCategoria(categoria.id);
  1321. setState(() {
  1322. categoriaSeleccionada = categoria;
  1323. });
  1324. },
  1325. style: ElevatedButton.styleFrom(
  1326. backgroundColor: isSelected ? AppTheme.tertiary : Colors.grey,
  1327. foregroundColor:
  1328. isSelected ? AppTheme.quaternary : AppTheme.secondary,
  1329. ),
  1330. child: Text(categoria.nombre!),
  1331. ),
  1332. );
  1333. },
  1334. ),
  1335. ),
  1336. );
  1337. }
  1338. Widget _buildSearchBar() {
  1339. return Padding(
  1340. padding: const EdgeInsets.all(8.0),
  1341. child: TextField(
  1342. controller: _searchController,
  1343. decoration: InputDecoration(
  1344. hintText: 'Buscar producto...',
  1345. prefixIcon: const Icon(Icons.search),
  1346. suffixIcon: IconButton(
  1347. icon: Icon(Icons.clear),
  1348. onPressed: () {
  1349. _searchController.clear();
  1350. _onSearchChanged('');
  1351. },
  1352. ),
  1353. border: OutlineInputBorder(
  1354. borderRadius: BorderRadius.circular(12.0),
  1355. ),
  1356. enabledBorder: OutlineInputBorder(
  1357. borderRadius: BorderRadius.circular(12.0),
  1358. borderSide: BorderSide(width: 1.5)),
  1359. focusedBorder: OutlineInputBorder(
  1360. borderSide: BorderSide(color: Colors.black),
  1361. borderRadius: BorderRadius.circular(12.0),
  1362. ),
  1363. ),
  1364. onChanged: _onSearchChanged,
  1365. ),
  1366. );
  1367. }
  1368. }