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
new TextField( | |
decoration: new InputDecoration( | |
hintText: 'Choose a book', | |
), | |
onChanged: (string) => (subject.add(string)), | |
), |
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
new Expanded( | |
child: new ListView.builder( | |
padding: new EdgeInsets.all(8.0), | |
itemCount: _items.length, | |
itemBuilder: (BuildContext context, int index) { | |
return new Card( | |
child: new Padding( | |
padding: new EdgeInsets.all(8.0), | |
child: new Row( | |
children: <Widget>[ |
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
@override | |
void initState() { | |
super.initState(); | |
subject.stream.debounce(new Duration(milliseconds: 600)).listen(_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 _addBook(dynamic book) { | |
setState(() { | |
_items.add(new Book(book["volumeInfo"]["title"], book["volumeInfo"]["imageLinks"]["smallThumbnail"])); | |
}); | |
} |
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) |
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
class BookDatabase { | |
static final BookDatabase _bookDatabase = new BookDatabase._internal(); | |
final String tableName = "Books"; | |
Database db; | |
static BookDatabase get() { | |
return _bookDatabase; | |
} |
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
/// Get a book by its id, if there is not entry for that ID, returns null. | |
Future<Book> getBook(String id) async{ | |
var result = await db.rawQuery('SELECT * FROM $tableName WHERE ${Book.db_id} = "$id"'); | |
if(result.length == 0)return null; | |
return new Book.fromMap(result[0]); | |
} |
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
/// Inserts or replaces the book. | |
Future updateBook(Book book) async { | |
await db.inTransaction(() async { | |
await db.rawInsert( | |
'INSERT OR REPLACE INTO ' | |
'$tableName(${Book.db_id}, ${Book.db_title}, ${Book.db_url}, ${Book.db_star}, ${Book.db_notes})' | |
' VALUES("${book.id}", "${book.title}", "${book.url}", ${book.starred? 1:0}, "${book.notes}")'); | |
}); | |
} |
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
class BookCard extends StatefulWidget { | |
BookCard(this.book); | |
final Book book; | |
@override | |
State<StatefulWidget> createState() => new BookCardState(); |
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
class BookCardState extends State<BookCard> { | |
Book bookState; | |
@override | |
void initState() { | |
super.initState(); | |
bookState = widget.book; |
OlderNewer