This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
floatingActionButton: FloatingActionButton( | |
onPressed: () async { | |
/* | |
* Esperamos a que vuelva de la ruta y refrescamos | |
* los clientes. No encontré otra manera de hacer que | |
* se escuche cuando se regresa de la ruta | |
* */ | |
// await navigatorKey.currentState | |
// .push(MaterialPageRoute(builder: (context) => AgregarVenta())); | |
// this.obtenerVentas(); | |
}, | |
child: Icon(Icons.add), | |
), | |
appBar: AppBar( | |
title: Text("Ventas"), | |
), | |
body: (cargando) | |
? Center( | |
child: CircularProgressIndicator(), | |
) | |
: ListView.builder( | |
itemCount: ventas == null ? 0 : ventas.length, | |
itemBuilder: (BuildContext context, int index) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
ListTile( | |
title: Builder( | |
builder: (context) { | |
double total = 0; | |
for (var i = 0; | |
i < ventas[index]["productos"].length; | |
i++) { | |
double cantidad = double.parse( | |
ventas[index]["productos"][i]["cantidad"]); | |
double precio = double.parse( | |
ventas[index]["productos"][i]["precio"]); | |
total += (cantidad * precio); | |
} | |
return Text("\$" + formateador.format(total)); | |
}, | |
), | |
subtitle: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.only( | |
left: 0, | |
top: 0, | |
right: 5, | |
bottom: 0, | |
), | |
child: Text( | |
"Fecha", | |
style: TextStyle(fontWeight: FontWeight.bold), | |
), | |
), | |
Text(ventas[index]["created_at"] | |
.toString() | |
.substring( | |
0, | |
ventas[index]["created_at"] | |
.toString() | |
.indexOf(".0000")) | |
.replaceFirst("T", " ")), | |
], | |
), | |
Row( | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.only( | |
left: 0, | |
top: 0, | |
right: 5, | |
bottom: 0, | |
), | |
child: Text( | |
"Cliente", | |
style: TextStyle(fontWeight: FontWeight.bold), | |
), | |
), | |
Text(ventas[index]["cliente"]["nombre"]), | |
], | |
), | |
], | |
), | |
), | |
ButtonBar( | |
children: <Widget>[ | |
FlatButton( | |
child: Icon( | |
Icons.zoom_in, | |
color: Colors.blue, | |
), | |
onPressed: () { | |
navigatorKey.currentState.push( | |
MaterialPageRoute( | |
builder: (context) => DetalleDeVenta( | |
idVenta: this.ventas[index]["id"], | |
), | |
), | |
); | |
}, | |
), | |
Builder( | |
builder: (context) => FlatButton( | |
child: Icon( | |
Icons.delete, | |
color: Colors.red, | |
), | |
onPressed: () { | |
showAlertDialog( | |
context, | |
FlatButton( | |
child: Text("Cancelar"), | |
onPressed: () { | |
navigatorKey.currentState.pop(); | |
}, | |
), | |
FlatButton( | |
child: Text("Sí, eliminar"), | |
onPressed: () async { | |
await eliminarVenta( | |
this.ventas[index]["id"].toString()); | |
navigatorKey.currentState.pop(); | |
this.obtenerVentas(); | |
Scaffold.of(context).showSnackBar( | |
SnackBar( | |
content: Text('Venta eliminada'), | |
duration: Duration(seconds: 1), | |
), | |
); | |
}, | |
), | |
"Eliminar venta", | |
"¿Realmente deseas eliminar la venta? esto no se puede deshacer"); | |
}, | |
), | |
), | |
], | |
), | |
Divider(), | |
], | |
); | |
}, | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment