Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 20:15
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/a8bc1c78522550eb702656f560a950c8 to your computer and use it in GitHub Desktop.
Save parzibyte/a8bc1c78522550eb702656f560a950c8 to your computer and use it in GitHub Desktop.
Future<bool> obtenerProducto(int idProducto) 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.get(
"$RUTA_API/producto/$idProducto",
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer $posibleToken',
},
);
log("Response es 200?");
log((response.statusCode == 200).toString());
Map<String, dynamic> productoRaw = json.decode(response.body);
setState(() {
cargando = false;
_codigoBarras.text = productoRaw["codigo_barras"];
_descripcion.text = productoRaw["descripcion"];
_precioCompra.text = productoRaw["precio_compra"];
_precioVenta.text = productoRaw["precio_venta"];
_existencia.text = productoRaw["existencia"];
});
return response.statusCode == 200;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment