Favoriting Items in Flutter Using Sqlite

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Favoriting Items in Flutter Using Sqlite



I want to be able to favorite/mark items in a already populated local sqlite database to display on a "favorites page" that shows a list of favorited items.



In this sqlite database, I have a table of genres and a table of books relating to a specific genre. I am not using a model "book" class to display book information in a list. I have using a rawQuery to place a ROW of book information into a List to display that book information in a bookView page. Like so..


Future getDescriptionData() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "asset_sample_sqlite.db");
ByteData data =
await rootBundle.load(join("assets", "sample_sqlite.db"));
List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await new File(path).writeAsBytes(bytes);
Database db = await openDatabase(path);
await db
.rawQuery('SELECT * FROM books WHERE id = "$widget.id"') // id passed on from previous page where it shows a list of books
.then((results) {
setState(()
loading = false;
initialized = true;
bookDescription = results;
);



then I display the information like so..


body: Padding(
padding: const EdgeInsets.all(8.0),
child: new Center(
child: !loading
? new ListView.builder(
itemCount: bookDescription.length,
itemBuilder: (BuildContext context, int index)
return new Card(
elevation: 2.0,
child: new ListTile(
title: new Text($bookDescription[index]['title']",
textAlign: TextAlign.center,
),
subtitle: new Text(
"$bookDescription[index]['summary']",
),
),
),
),
);
,
)



What is the best method to include an iconButton in this card, and then have an option to favorite this "book" to add it to a shortlist of books that are favorited in a different favorite book list page?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard