Is Hydrated Bloc good for storing more complex data? - flutter

I'm a newbie in flutter and recently started learning Bloc with flutter_bloc package. I want to store some data in local storage.
I have found the hydrated_bloc package, and here comes my question: "Is HydratedBloc good to store more complex data (like: users list, their details, saved todos, notes etc.) Or it's just created to persist simple state data (like: chosen theme (dark or liqht), last page where user left)?".
How can I best store data localy when using bloc?

Yes, You can use it to store complex data. Because, As the package itself states that it is built on top of hive for a platform-agnostic which is faster than shared preferences.
You can take a look at the image below to see the difference.

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

Which package is better flutter_secure_storage or getx in my scenario?

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.

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

Why should I use Bloc with a Calendar instead of a Static Map?

In Flutter, I want to use a calendar from the table_calendar package in order to set shifts and assign employees to them.
Also to do so I am using a local database from the sqflite package.
I have seen a few tutorials online, e.g., Database Storage in Flutter using Sqflite, that combine the database with Bloc technology.
For my calendar, I need a Map<DateTime,List<dynamic>> to control the events. As of now, I used a static map that I would use in different classes, e.g., shift_form and shift_calendar.
The Bloc implementation would start somehow like this:
class ShiftBloc extends Bloc<ShiftEvent, Map<DateTime,List<dynamic>> {...
Why should I use Bloc instead of a static Map?
Also is it even possible to use a Bloc as a Map data structure? Edit: -> Yes it
is
But how should I implement Blocs for the Streams that I am getting from Firestore as a Map instead of a List?
P.S. I am using the Flutter Firestore Todos Tutorial structure.
As a general rule, you never "have" to use BLoC for anything.
BLoC and other State Management strategies are meant to make it easier to deal with data that multiple parts of your App need at the same time, and need to be updated when that data changes.
For simple Widgets, low dependency on data, a simple setState should be more than enough and there's nothing wrong using it.
Some people just use State Management with everything without stopping to analyze the problem at hand, this makes the code more confusing for not reason.
If your Map is local, just use it locally, if you need it in several places, than avoid using it as a global variable as this makes testing a lot harder.
Remember, a BLoC is just a class with Streams as ouputs and Syncs as inputs, the Firebase Firestore class already provides you with a Stream, so your BLoC could be just a Stream transformation adapting the data on Firestore to your Map. I can't really say how to make this as I am not aware with your data.

What to use ? Bloc or Moor in Flutter

So, I am trying to create a project where I am supposed to Call Web API and store the data in my local storage. Which should still have even if the app is killed and then re-opened.
FYI, data will be large and I will require a significant amount of space in the mobile device.
i will be using firebase for login, the payment transaction and etc.
this is my first answer, I hope to help you.
BloC & Moor are not synonyms, BloC is a reactive state management solution that allows you to better manage the interaction between logic and widgets in a reactive way. Moor is a layer between sqlite and your application, it allows you to deal with sqlite using dart code by reacting to database changes through Streams and Futures
I think you do not need to choose one of the two, if your application is going to handle large amounts of data and will grow exponentially I recommend that you implement both as they complement each other, by designing a SOLID structure.