我正在努力將資料保存在本地存盤中,但是當我將資料插入到sqlite db 時,它不會立即更新,但在我按下重新加載按鈕后它會更新。我該怎么辦?
uj5u.com熱心網友回復:
I have faced the same problem what you have to do is create Provider class then instantiate the database in that class then call the method like this
{
// this is method in provider class to get the task inserted in the db
Future loadTaskList() async {
_isLoading = true;
notifyListeners();
_taskList = await db.getTasks();
_isLoading = false;
notifyListeners();
}
}
use the same format for update,delete and insert data to the db after this call the provider class in the main.dart file like this
{
ChangeNotifierProvider(
create: (ctx) => InputData()..loadTaskList(),
),
}
then just use Consumer or Provider when you access the methods.
**This work perfectly for me!**
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/440737.html
下一篇:使用單獨的字典更改字典鍵?
