'Flutter - Why does it only add the last table of SQLite in the list
I have the SQLite database that has (68) tables and local JSON that has all the names of tables and some other details, I have View in my project I called it SearchView and I need to search anything in my database by using onSubmitted in TextField widget.
Problem:
When I click onSubmitted the button, it only searches the last table of the database and does not search all the 68 tables!
Code:
List<BooksModel>? books; // SQLite Model
List<LibraryModel>? library; // JSON Model
bool isLoad = false;
@override
void initState() {
super.initState();
loadBooks();
}
Future loadBooks() async {
setState(() => isLoad = true);
library = await LibraryService.lib.getLibrary();
for (var i = 0; i < library!.length; i++) {
books = await DatabaseService.db.getBooks(library![i].dbName ?? "");
}
print(books!.toList().length);
setState(() => isLoad = false);
}
Stopwatch stopwatch = Stopwatch(); // Just test how long it takes to show the search result
onSubmitted: (value) {
setState(() {
stopwatch.reset();
stopwatch.start();
});
print("VALUE: $value");
String search = SearchService.search.convert(value);
var searchResult = books!
.where((x) => SearchService
.search.convert(x.pageText ?? "")
.contains(search))
.toList();
setState(() {
print("Search Result: ${searchResult.length}");
stopwatch.stop();
print("Time of Result: ${stopwatch.elapsed.toString()}");
});
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
