Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 20:12
Show Gist options
  • Save parzibyte/d787d3a00b32db122de9dc3b2e2e428c to your computer and use it in GitHub Desktop.
Save parzibyte/d787d3a00b32db122de9dc3b2e2e428c to your computer and use it in GitHub Desktop.
Future<bool> agregarProducto(Producto producto) async {
setState(() {
cargando = true;
});
log("Obteniendo prefs...");
final prefs = await SharedPreferences.getInstance();
String posibleToken = prefs.getString("token_api");
log("Posible token: $posibleToken");
if (posibleToken == null) {
log("No hay token");
return false;
}
log("Haciendo petición...");
final http.Response response = await http.post(
"$RUTA_API/producto",
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer $posibleToken',
},
body: jsonEncode(<String, String>{
'codigo_barras': producto.codigoBarras,
'descripcion': producto.descripcion,
'precio_compra': producto.precioCompra,
'precio_venta': producto.precioVenta,
'existencia': producto.existencia,
}),
);
log("Response es 200?");
log((response.statusCode == 200).toString());
setState(() {
cargando = false;
});
return response.statusCode == 200;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment