Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3f64ad11cf3c42b9cbb136a1181e04ef to your computer and use it in GitHub Desktop.
Save parzibyte/3f64ad11cf3c42b9cbb136a1181e04ef to your computer and use it in GitHub Desktop.
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () async {
/*
* Esperamos a que vuelva de la ruta y refrescamos
* los productos. No encontré otra manera de hacer que
* se escuche cuando se regresa de la ruta
* */
await navigatorKey.currentState
.push(MaterialPageRoute(builder: (context) => AgregarProducto()));
this.obtenerProductos();
},
child: Icon(Icons.add),
),
appBar: AppBar(
title: Text("Productos"),
),
body: (cargando)
? Center(
child: CircularProgressIndicator(),
)
: ListView.builder(
itemCount: productos == null ? 0 : productos.length,
itemBuilder: (BuildContext context, int index) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: Text(productos[index]["descripcion"]),
subtitle: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
left: 0,
top: 0,
right: 5,
bottom: 0,
),
child: Text(
"Código",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text(productos[index]["codigo_barras"]),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
left: 0,
top: 0,
right: 5,
bottom: 0,
),
child: Text(
"Compra",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text("\$" + productos[index]["precio_compra"]),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
left: 0,
top: 0,
right: 5,
bottom: 0,
),
child: Text(
"Venta",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text("\$" + productos[index]["precio_venta"]),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
left: 0,
top: 0,
right: 5,
bottom: 0,
),
child: Text(
"Existencia",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text(productos[index]["existencia"]),
],
),
],
),
// subtitle: Text(productos[index]["codigo_barras"] + "\nxd"),
),
ButtonBar(
children: <Widget>[
FlatButton(
child: Icon(
Icons.edit,
color: Colors.amber,
),
onPressed: () async {
await navigatorKey.currentState.push(
MaterialPageRoute(
builder: (context) => EditarProducto(
idProducto: this.productos[index]["id"],
),
),
);
this.obtenerProductos();
},
),
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 eliminarProducto(this
.productos[index]["id"]
.toString());
navigatorKey.currentState.pop();
this.obtenerProductos();
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Producto eliminado'),
duration: Duration(seconds: 1),
),
);
},
),
"Eliminar producto",
"¿Realmente deseas eliminar el producto ${this.productos[index]["descripcion"]}? esto no se puede deshacer");
},
),
),
],
),
Divider(),
],
);
},
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment