Home > Back-end >  how to update data instantly from sqflite db
how to update data instantly from sqflite db

Time:03-12

I was working on to save data on the local storage in flutter but when I insert data to the sqlite db it doesn't update instantly but it will after I pressed the reload button. what shall I do?

CodePudding user response:

        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!**
  • Related