Created
April 9, 2020 19:58
-
-
Save parzibyte/26a913fb32dc4a4a65bbfd9e745692eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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