Created
January 16, 2021 17:07
-
-
Save AmineLAHRIM/290a3d618ae4478eb0ea1463dbeb1b0a 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
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