Managing flutter app and flutter web data locally - flutter

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.

Related

Rest API data stored in locally - Flutter

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).

How to handle data for integration tests in Flutter with Firebase Realtime Database?

I am in the process of adding integration tests for my flutter app (Android & iOS).
I am planning on having a sort of BDD test structure, with the Given parts implemented as data that I want to load inside the database.
I am using the Firebase emulators to launch a local instance, following the production rules. However, I can see of no easy way to bypass the rules to populate the database before running the tests.
there is an import folder option from firebase emulator, but this would
decouple completely the data from the tests, making it very hard to adjust one without breaking the other
imply either a restart of the emulator between each test, or a database state containing many different cases, with each test using different parts of the data.
using the firebase sdk from the flutter code seemed ideal, however there's a flutter plugin that seems not maintained and pre null-safety, and no official option
manually creating the desired state from within the app with a logged-in user (or four) before performing the actual test (the slowest and less reliable way)
Am I missing something obvious? Is there a better option with the emulator to front-load data before a given test? A good way to manage this data? Thank you in advance!

What is the easiest way to fetch data dynamically from a cloud storage to a flutter app

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.

How to create an app and save local data using dart and flutter?

I'm a beginner programmer on the dart and flutter. I want to create an app to manage my small shop and save data on a physical device. I searched for any code samples, but I couldn't find anything. Any ideas or suggestions from Flutter professionals to begin my project will be really helpful.
You can either use sharedPrefernce plugin for storing data. But data may be persisted to disk asynchronously, and there is no guarantee that writes will be persisted to disk after returning, so this plugin must not be used for storing critical data.
Another option is Hive fast key-value database written in pure Dart.
you can also explore other options like sqllite or firebase_database
flutter create appname - This can be used to create flutter app

Using other languages with Flutter

I have been working with flutter for a couple of months now and it seems that there isn't really too much to work on an app for back-end or advanced functionality. I love using Flutter to help me design the UI but I want to use another language to help me do some other stuff. For example, I want to display a full-screen camera page (almost like Snapchat) or like send a direct message to another user through the app. Do I even need another language to do stuff like this? I am not an advanced programmer. I just want to create simple applications that can process and store a little bit of stuff.
You can easily do the mentioned stuff in Flutter/Dart.
Check out Firebase Messaging for direct messages and SQLite to store information on user devices.
For saving data locally,
You can use SqlFlite, a plugin with the help of which you can easily store and manage your database.
For saving data on the backend, so that other users can also access it when necessary, like the one you mentioned in a comment (..food ordering app)..you can use Firebase
Firebase has all you need.
Link to firebase :- https://firebase.google.com/
When your data is stored on a cloud, you don't need to hard code anything, for example, about the food ordering app you mentioned, you can make use of variables, in which you can store the values. So that when the owner changes the price, it gets updated.