Last active
December 10, 2018 14:02
-
-
Save hjJunior/8243283d316d503370a740cdb7d97947 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 'package:http/http.dart' as http; | |
import 'dart:convert'; | |
import '../models/beer.dart'; | |
Future<Stream<Beer>> getBeers() async { | |
final String url = 'https://api.punkapi.com/v2/beers'; | |
final client = new http.Client(); | |
final streamedRest = await client.send( | |
http.Request('get', Uri.parse(url)) | |
); | |
return streamedRest.stream | |
.transform(utf8.decoder) | |
.transform(json.decoder) | |
.expand((data) => (data as List)) | |
.map((data) => Beer.fromJSON(data)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment