Skip to content

Instantly share code, notes, and snippets.

@AmineLAHRIM
Created January 16, 2021 17:07
Show Gist options
  • Save AmineLAHRIM/290a3d618ae4478eb0ea1463dbeb1b0a to your computer and use it in GitHub Desktop.
Save AmineLAHRIM/290a3d618ae4478eb0ea1463dbeb1b0a to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<Album> fetchAlbum() async {
final response = await http.get(
'https://jsonplaceholder.typicode.com/albums/1',
headers: {HttpHeaders.authorizationHeader: "Bearer your_api_token_here"},
);
final responseJson = jsonDecode(response.body);
return Album.fromJson(responseJson);
}
class Album {
final int userId;
final int id;
final String title;
Album({this.userId, this.id, this.title});
factory Album.fromJson(Map<String, dynamic> json) {
return Album(
userId: json['userId'],
id: json['id'],
title: json['title'],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment