Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Future<bool> obtenerVenta(int idVenta) 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/venta/$idVenta",
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer $posibleToken',
},
);
log("Response es 200?");
log((response.statusCode == 200).toString());
detalle = json.decode(response.body);
double t = 0;
if (detalle != null) {
for (var x = 0; x < detalle["productos"].length; x++) {
t += (double.parse(detalle["productos"][x]["cantidad"]) *
double.parse(detalle["productos"][x]["precio"]));
}
}
setState(() {
cargando = false;
total = t;
});
return response.statusCode == 200;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.