Home > database >  how to Store app data and prevent data to get lost and also make app work at background in flutter
how to Store app data and prevent data to get lost and also make app work at background in flutter

Time:12-23

I am a intermediate flutter developer and working on my first commercial app And I have almost created whole app ui but problem is when i close my app all data get lost . so how can i prevent it how can i make my app work at background when app is close like in clock app . In clock app even if app is closed then also we get alarm at the timing we set . It is not possible to provide whole app code thats why i am explaining it in words . Hope you guys will understand the problem and provide best answer .

CodePudding user response:

To store data locally you can use local storage options like Database such as SQFlite, Hive etc or SharedPreference that will save your data locally and to run background process you need to use MethodChannel and write platform specific code or you also have the options to use Isolates. You may read more using this link

https://docs.flutter.dev/development/packages-and-plugins/background-processes

CodePudding user response:

You can use internal data base concept to save user data like JWT key , user id, first name ,last name or app content for offline usage like blog articles ,pos system data for offline usage

  • Use Shared preferences to save basic data like user data, JWT but less secure
  • but if you need save complex data and need query or filter you can use hive and you can keep data more secure

And Alarm is totally deferent approach,

when we schedule alarm,alarm manager schedule task on system alarm services and wakeup app with intent and flutter Isolate class

CodePudding user response:

We divide your question into two parts.

Question 01: How to store data locally :

These are some of the popular databases that you can use with flutter. And much more available at pub.dev. But you want to use a database with your task. As an example simply store the user name or user id you can use Shared preferences

Question 02: Make Alarm Application :

For android applications, you can simply use android_alarm_manager I suggest you take a deep look at the flutter docs about the subject:

Background processes

If you need to show scheduled messages, use local notifications:

I think by referring to these links you can get an idea.

  • Related