pedido_detalle_screen.dart 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import 'package:intl/intl.dart';
  2. import 'package:yoshi_papas_app/themes/themes.dart';
  3. import 'package:yoshi_papas_app/views/pedido/pedido_ticket.dart';
  4. import 'package:flutter/material.dart';
  5. import '../../models/models.dart';
  6. class PedidoDetalleScreen extends StatelessWidget {
  7. final Pedido pedido;
  8. String formatCurrency(double amount) {
  9. final format = NumberFormat("#,##0.00", "es_MX");
  10. return format.format(amount);
  11. }
  12. const PedidoDetalleScreen({Key? key, required this.pedido}) : super(key: key);
  13. @override
  14. Widget build(BuildContext context) {
  15. double total = pedido.productos.fold(0, (previousValue, element) {
  16. double productTotal = element.cantidad! *
  17. (double.tryParse(element.producto?.precio ?? '') ?? 0.0);
  18. double toppingsTotal = element.toppings.fold(0, (toppingTotal, topping) {
  19. return toppingTotal +
  20. (double.tryParse(topping.topping?.precio ?? '') ?? 0.0) *
  21. element.cantidad!;
  22. });
  23. return previousValue + productTotal + toppingsTotal;
  24. });
  25. return Scaffold(
  26. appBar: AppBar(
  27. title: Text(
  28. 'Detalle del Pedido ${pedido.folio}',
  29. style: TextStyle(fontWeight: FontWeight.w500),
  30. ),
  31. ),
  32. body: SingleChildScrollView(
  33. padding: const EdgeInsets.all(12.0),
  34. child: Column(
  35. children: [
  36. Card(
  37. elevation: 4,
  38. color: Colors.white,
  39. child: Column(
  40. children: [
  41. ListTile(
  42. title: Text(
  43. 'Cliente: ${pedido.nombreCliente}',
  44. style: TextStyle(
  45. fontWeight: FontWeight.bold, fontSize: 22),
  46. ),
  47. subtitle: Text(
  48. 'Comentarios: ${pedido.comentarios}',
  49. style: TextStyle(
  50. fontSize: 20, fontWeight: FontWeight.w500),
  51. ),
  52. ),
  53. ListTile(
  54. title: Text(
  55. 'Estado del Pedido: ${pedido.estatus}',
  56. style: TextStyle(
  57. fontSize: 22,
  58. fontWeight: FontWeight.bold,
  59. ),
  60. ),
  61. )
  62. ],
  63. )),
  64. SizedBox(height: 10),
  65. Card(
  66. elevation: 4,
  67. color: Colors.white,
  68. child: Padding(
  69. padding: const EdgeInsets.all(8.0),
  70. child: Column(
  71. crossAxisAlignment: CrossAxisAlignment.start,
  72. children: [
  73. Text('Productos',
  74. style: TextStyle(
  75. fontSize: 22, fontWeight: FontWeight.bold)),
  76. const SizedBox(height: 15),
  77. ListView.builder(
  78. shrinkWrap: true,
  79. physics: NeverScrollableScrollPhysics(),
  80. itemCount: pedido.productos.length,
  81. itemBuilder: (context, index) {
  82. final producto = pedido.productos[index];
  83. return Padding(
  84. padding: const EdgeInsets.symmetric(vertical: 4.0),
  85. child: Column(
  86. crossAxisAlignment: CrossAxisAlignment.start,
  87. children: [
  88. Row(
  89. children: [
  90. Expanded(
  91. flex: 6,
  92. child: Text(
  93. producto.producto?.nombre ??
  94. "Producto no especificado",
  95. style: TextStyle(
  96. fontWeight: FontWeight.bold,
  97. fontSize: 17),
  98. overflow: TextOverflow.ellipsis,
  99. ),
  100. ),
  101. Expanded(
  102. flex: 1,
  103. child: Text(
  104. 'x${producto.cantidad}',
  105. style: TextStyle(
  106. fontWeight: FontWeight.w500,
  107. fontSize: 17),
  108. textAlign: TextAlign.center,
  109. ),
  110. ),
  111. Expanded(
  112. flex: 2,
  113. child: Text(
  114. '\$${formatCurrency(double.tryParse(producto.producto?.precio ?? '0.0') ?? 0.0)}',
  115. style: TextStyle(
  116. fontWeight: FontWeight.w500,
  117. fontSize: 17),
  118. textAlign: TextAlign.right,
  119. ),
  120. ),
  121. ],
  122. ),
  123. if (producto.toppings.isNotEmpty)
  124. Padding(
  125. padding: const EdgeInsets.only(top: 4.0),
  126. child: Column(
  127. crossAxisAlignment:
  128. CrossAxisAlignment.start,
  129. children:
  130. producto.toppings.map((topping) {
  131. return Padding(
  132. padding: const EdgeInsets.symmetric(
  133. vertical: 2.0),
  134. child: Row(
  135. children: [
  136. Text(
  137. '- ${topping.topping?.nombre ?? "Topping no especificado"}',
  138. style: TextStyle(
  139. fontSize: 15,
  140. color: Colors.grey[600]),
  141. ),
  142. Spacer(),
  143. Text(
  144. '\$${formatCurrency(double.tryParse(topping.topping?.precio ?? '0.0') ?? 0.0)}',
  145. style: TextStyle(
  146. fontSize: 15,
  147. color: Colors.grey[600]),
  148. ),
  149. ],
  150. ),
  151. );
  152. }).toList(),
  153. ),
  154. ),
  155. ],
  156. ),
  157. );
  158. },
  159. ),
  160. Divider(),
  161. Padding(
  162. padding: const EdgeInsets.symmetric(vertical: 8.0),
  163. child: Row(
  164. mainAxisAlignment: MainAxisAlignment.end,
  165. children: [
  166. Text('Total: \$${formatCurrency(total)}',
  167. style: TextStyle(
  168. fontSize: 16, fontWeight: FontWeight.bold)),
  169. ],
  170. ),
  171. ),
  172. ],
  173. ),
  174. ),
  175. ),
  176. const SizedBox(height: 20),
  177. Align(
  178. alignment: Alignment.centerLeft,
  179. child: ElevatedButton.icon(
  180. icon: Icon(
  181. Icons.receipt_long_outlined,
  182. color: AppTheme.quaternary,
  183. size: 30,
  184. ),
  185. onPressed: () => imprimirTicketsJuntos(pedido),
  186. label: Text(
  187. 'Imprimir Ticket',
  188. style: TextStyle(
  189. fontWeight: FontWeight.w500,
  190. fontSize: 18,
  191. color: AppTheme.quaternary),
  192. ),
  193. style: ElevatedButton.styleFrom(
  194. padding: EdgeInsets.fromLTRB(50, 20, 50, 20),
  195. primary: AppTheme.tertiary,
  196. ),
  197. ),
  198. )
  199. ],
  200. )),
  201. );
  202. }
  203. }