Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 19:58
Show Gist options
  • Save parzibyte/26a913fb32dc4a4a65bbfd9e745692eb to your computer and use it in GitHub Desktop.
Save parzibyte/26a913fb32dc4a4a65bbfd9e745692eb to your computer and use it in GitHub Desktop.
Future<String> obtenerProductos() 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 "No hay token";
}
log("Haciendo petición...");
var response = await http.get(
"$RUTA_API/productos",
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer $posibleToken',
},
);
this.setState(() {
productos = json.decode(response.body);
this.cargando = false;
});
return "Success!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment