I have a requirement to store data locally to use within a Flutter mobile application. This stored data will be used for when the device is offline and will need to be updated, whilst offline.
On initial login of the application, data must be pulled from a REST API and stored locally to be displayed within the app.
Does anyone have any pointers as to what is the best method for this? I've looked at Sqflite but i can't seem to see any tutorials or documentation on setting this up using an API to 'fill' the data initially.
Any advice would be appreciated.
There are many ways to go about this.
One option is simply using dio, which has caching support built in.
Or, you could use something like hive or SharedPreferences along with http to to persist the data yourself (depending on what level of control you want/need).
You could also encapsulate the data in a state management solution like riverpod (specifically a FutureProvider in this case) which will soon have offline persistence support.
If building an application from scratch, I'd recommend the riverpod route (and it will soon have that offline persistence support).
Related
I am looking for a way to fetch data to my flutter app which can be adjusted and modified dynamically after deploying the app. As an example, if I want to change the images of the carousel depending on promotions or launch new books to the digital library. I need an economic option to host the data in cloud storage and fetch it from there.
I have considered firebase as well as google drive, but have yet to find a good guide. being a beginner and having concerns about security I want some expert advice if possible.
*edit-
Seeing many a tutorial I assume there is no better way than linking file URLs from the
Cloud Storage. So to dynamically change those is it possible to refer the URLs to some excel sheet fields to obtain URLs. Those fields can certainly be adjusted then without any hard coding. but the question is how to refer to such a sheet file? *
I also want to segregate the users into paid and free users, I have successfully proceeded with the authentication with firebase but still don't understand(I do have some concepts but don't know where to do that) how to put them in groups and impose limitations on them about accessing the data. any guidance, links and helpful advice will be cordially appreciated.
According to what you are looking for, I highly recommend you to use Firebase Remote Config, which is a cloud tool that allows you to modify your app's functionality and appearance without forcing users to download an update. You define in-app default values that control the functionality and appearance of your app when you use Remote Config. Then, for all app users or for subsets of your user base, you may utilize the Firebase console or the Remote Config backend APIs to modify in-app default values.
Your program can control when updates are applied, and it can check for updates regularly and apply them with minimal performance impact.
Remote Config comes with a client library that takes care of essential functions like fetching parameter values and caching them while still allowing you to manage when new values are active and how they affect the user experience in your app.
Here is a tutorial that uses Flutter and Firebase Remote Config that could also help you.
I was working on a project to create a flutter to-do app to store data locally on mobile devices but I am not sure how to save data on local storage or something similar on the web.
So, I want to save the data locally if it is a mobile device and save the data on local storage if it's accessed via the web.
I don't know where to start, please advise.
Options
You can use shared_preferences as it uses shared_preferences_android, shared_preferences_ios and shared_preferences_web (using IndexedDB) for the different platforms, note that this is not relevant for you directly as shared_preferences switches accordingly to the required platform.
Alternatively you can also use hive, as it also supports the web (via IndexedDB) and of course all other Platforms similar to shared_preferences.
The last option that also supports web is isar, it is however the most advanced of the three and is not well suited for this simple application at all.
Docs
All links link to their respective pub pages with enough docs. The only problem now is when to use which of the package.
Which to use
The flutter community is pretty divided over this, but as you can see shared_preferences has more likes and is from the flutter team at google themselves. However shared_preferences is very basic and if you are considering to save your own class objects (which is probably of use in an todo app) hive has a steeper learning curve to do so, but imo its better than just serialising it with and from json.
Of course json is completely fine, more so as you are probably a beginner, but for more complex applications hive (and if it gets really complex isar) is much better imo.
I am using the https://pub.dev/packages/flutter_secure_storage (uses Await/Async functions) to store a value and later retrieve it. Note that everytime I open the app, I will update the value. I just use this for the purpose of storing and retrieving the values while the app is open. NOT to store so that when the app is closed and then opened again, I can retrieve it.
Now I have learned about the https://pub.dev/packages/get which is promising since I can make my variables observable which seems easier to use with less coding.
Now I just want to ask for expert advice on those who know both flutter packages whether it is worth to migrate from using flutter_secure_storage to get. Thanks!
hi buddy flutter_secure_storage is a package that is used if you want to store your data in encrypted form this is used when you are dealing with very sensitive data like you are creating an application for banking service so you need super security where as the getX package is a all-in-one package for state management, route management, Internationalization, API calling etc, it has lots of features and very easy to use. It can also Store your data but Not in Encrypted form it is basically an alternative to Shared_Preference package, so if you want to store data in Encrypted format then go for flutter_secure_storage and if you don't need Encrypted storage then you can use getX. I would definitely recommend to use getX not only for storage you can you also use it for state management and lots of other features.
I came across this link trying to figure out how to access the REST api of my firebase database and stream it to my app. I can get/send data manually, but for my app I can't use the firebase api (because it is an app clip), so I'm trying to do it with native tools and rest, but the issue I'm running into is getting the configuration right (per this info) and actually parsing the incoming info and updating my app. I'm so lost and could use some help just figuring out how to make the code in the sample work, especially since I'm using swift ui as well.
Any help is appreciated, thanks!
Apparently App Clips do not allow sockets connections, so (while Google rewrites their sdk to comply), I migrated my database to Realtime Database (since it was a better fit for us usage-wise), and have been using standard rest for sending and getting data, and for the "listener" functionality I have been using IKEventSource that listens to server-side events and updates them accordingly in my app clip. Seems to be a pretty good workaround so far.
Currently, I have a flutter app using Spring Boot Framework with MongoDB. I want to add Offline functionality to the application.
App Functionality:
User fills various forms(personal details, family member details, etc).
Use Case: When the user fills the Personal Details Form fields like 'name', 'dob' are filled manually and location (selected using the dropdown(GET APIs)).
The internet connection might be gone while filling these forms.
How can I make the application offline ready?
One way that I thought of is storing all the data using any local database like SQLite but there can more than 10 Forms so it can be difficult for maintaining a lot of data. Moreover, how the data will sync with Backend?
Questions:
How to store data?
How to sync store data with Backend when the app comes Online?
Is there any other better approach to achieve this task?