Created
August 29, 2016 22:45
-
-
Save sethladd/10cca8e94f1ce75503f443d798e066eb 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
// Real libraries and modules. | |
library search; | |
import 'dart:async' show Future; | |
import 'package:flutter/http.dart' as http; | |
// Future (aka Promise), type annotations, and top-level functions! | |
// And yes, async/await without translators! | |
Future<List<SearchResult>> fetchResults(String query) async { | |
// single-quote strings, and string interpolation! | |
var uri = 'https://itunes.app.com/search?query=$query'; | |
// await in action, returns the result of a completed Future | |
var responseContents = await http.read(uri); | |
var jsonData = JSON.decode(responseContents); | |
// convert into a List<SearchResult> | |
return convertToModel(jsonData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment