Created
February 15, 2018 19:54
-
-
Save Norbert515/239aa28a77024d3bdc9791817ed0f413 to your computer and use it in GitHub Desktop.
textChanged
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
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