Skip to content

Instantly share code, notes, and snippets.

@sethladd
Created August 29, 2016 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethladd/10cca8e94f1ce75503f443d798e066eb to your computer and use it in GitHub Desktop.
Save sethladd/10cca8e94f1ce75503f443d798e066eb to your computer and use it in GitHub Desktop.
// 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