Created
September 22, 2019 17:43
-
-
Save soonsam123/8f8f42c16d5b01340501312fba57287f 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:convert'; | |
import 'package:http/http.dart' as http; | |
import 'package:bloc_pattern/models/user.dart'; | |
class UsersApiClient { | |
static const baseUrl = 'http://api.github.com'; | |
final http.Client httpClient; | |
UsersApiClient({this.httpClient}) | |
: assert(httpClient != null); | |
Future<List<User>> fetchUsers() async { | |
final List<User> allUsers = []; | |
http.Response response = await httpClient.get('$baseUrl/users'); | |
List<dynamic> responseData = jsonDecode(response.body); | |
responseData.forEach((singleUser) { | |
allUsers.add(User(login: singleUser['login'], id: singleUser['id'])); | |
}); | |
return allUsers; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment