sqlite issue while searching using search delegate

47 views
Skip to first unread message

Emily Walton

unread,
Feb 25, 2021, 1:09:21 AM2/25/21
to Flutter Development (flutter-dev)
I implemented an app where I search items in the sqlite database. The problem is caused when there are too many items in the database the app stops  working in the physical device maybe because of limited ram. I use a list to fetch all the items in the database and then I use .where to search in that list for a particular string query. Can there be another way so that the app runs perfectly fine independent of the number of entries in the database.
this function matches the query with the list
this.filteredItemSuggestionList = (query == '')
? itemSuggestionList
: this
.itemSuggestionList
.where((p) =>
p.name.toLowerCase().contains(query.toLowerCase()) |
p.description.toLowerCase().contains(query.toLowerCase()) |
p.date.toLowerCase().contains(query.toLowerCase()))
.toList();

this function stores all the data in the database in the list

Future<void> getItemsFromDb() async {
final Future<Database> dbFuture = databaseHelper.initializeDatabase();
dbFuture.then((database) {
Future<List<ItemClass>> itemListFuture = databaseHelper.getItemList();

itemListFuture.then((itemList) {
this.itemSuggestionList = itemList;

//this.fullCount = itemList.length;
});
});
}

Future<List<ItemClass>> getItemList() async {
var itemMapList = await getItemMapList(); // get Map list from the database
int count = itemMapList.length;
List<ItemClass> itemList = List<ItemClass>();
for (int i = 0; i < count; i++) {
itemList.add(
ItemClass.fromMapObject((itemMapList[i])),
);
}
return itemList;
}

Emily Walton

unread,
Feb 25, 2021, 1:11:56 AM2/25/21
to Flutter Development (flutter-dev)
basically i want that i can search the database without the app crashing if the number of entries in the sqflite database are large

--
You received this message because you are subscribed to a topic in the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flutter-dev/tH7tii68Upc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/d0d6805b-f4a6-4bec-8ddd-8615dc22bd24n%40googlegroups.com.

Guyren Howe

unread,
Feb 25, 2021, 1:52:05 AM2/25/21
to Flutter Development (flutter-dev), Emily Walton
Do the search in the database.That’s what it’s for.
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages