Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2020 19:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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(
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