Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 20:11
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/16e3da22f152da3bbf59d25ebb537a07 to your computer and use it in GitHub Desktop.
Save parzibyte/16e3da22f152da3bbf59d25ebb537a07 to your computer and use it in GitHub Desktop.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Agregar producto"),
),
body: Form(
key: _claveFormulario,
child: ListView(shrinkWrap: true, children: <Widget>[
Padding(
padding: EdgeInsets.all(16.0),
child: TextFormField(
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty) {
return 'Escribe el código de barras';
}
return null;
},
controller: _codigoBarras,
decoration: InputDecoration(
hintText: 'Escribe el código',
labelText: "Código de barras",
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'Escribe la descripción';
}
return null;
},
controller: _descripcion,
decoration: InputDecoration(
hintText: 'Escribe la descripción',
labelText: "Descripción",
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: TextFormField(
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty) {
return 'Escribe el precio de compra';
}
return null;
},
controller: _precioCompra,
decoration: InputDecoration(
hintText: 'Escribe el precio de compra',
labelText: "Precio de compra",
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: TextFormField(
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty) {
return 'Escribe el precio de venta';
}
return null;
},
controller: _precioVenta,
decoration: InputDecoration(
hintText: 'Escribe el precio de venta',
labelText: "Precio de venta",
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: TextFormField(
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty) {
return 'Escribe la existencia';
}
return null;
},
controller: _existencia,
decoration: InputDecoration(
hintText: 'Escribe la existencia',
labelText: "Existencia",
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: Builder(
builder: (context) => RaisedButton(
color: Colors.blue,
textColor: Colors.white,
child: cargando
? CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
)
: Text("Guardar"),
onPressed: () async {
if (!_claveFormulario.currentState.validate()) {
return;
}
if (cargando) {
return;
}
Producto p = new Producto(
_codigoBarras.text,
_descripcion.text,
_precioCompra.text,
_precioVenta.text,
_existencia.text);
await agregarProducto(p);
Scaffold.of(context)
.showSnackBar(
SnackBar(
content: Text('Producto guardado'),
duration: Duration(seconds: 1),
),
)
.closed
.then((razon) {
Navigator.of(context).pop();
});
},
),
),
),
]),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment