Skip to content

Instantly share code, notes, and snippets.

@Norbert515
Created February 15, 2018 19:54
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 Norbert515/239aa28a77024d3bdc9791817ed0f413 to your computer and use it in GitHub Desktop.
Save Norbert515/239aa28a77024d3bdc9791817ed0f413 to your computer and use it in GitHub Desktop.
textChanged
void _textChanged(String text) {
if(text.isEmpty) {
setState((){_isLoading = false;});
_clearList();
return;
}
setState((){_isLoading = true;});
_clearList();
http.get("https://www.googleapis.com/books/v1/volumes?q=$text")
.then((response) => response.body)
.then(JSON.decode)
.then((map) => map["items"])
.then((list) {list.forEach(_addBook);})
.catchError(_onError)
.then((e){setState((){_isLoading = false;});});
}
void _onError(dynamic d) {
setState(() {
_isLoading = false;
});
}
void _clearList() {
setState(() {
_items.clear();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment