I want to create a cookie for storage for a post request but i am facing challlenges on what to understand
I tried creating a cookie class and a handle cookie method but the creation doesnt seem to work and it stops my login from working
I want to create a cookie for storage for a post request but i am facing challlenges on what to understand
I tried creating a cookie class and a handle cookie method but the creation doesnt seem to work and it stops my login from working
2
Answers
For saving any data to local storage of the device you can use several solutions in flutter.
the most basic solution is shared preferences. You can store primitive data types and String lists with this. https://pub.dev/packages/shared_preferences
If you want to encrypt the storing data you can use https://pub.dev/packages/flutter_secure_storage.
For storing more complex data you can use a library like hive. Hive provides features for storing model classes. https://pub.dev/packages/hive. Also, you can encrypt stored data by hive and flutter_secure_storage combination.
As another option you can use sql database with sqflite plugin. https://pub.dev/packages/sqflite. If you are not going to manage really large amount of data, I recommend using hive instead of sqflite.
Especially for your problem I recommend flutter_secure_storage. It is a good option for storing simple and sensitive data.
To access the cookie you need the cookie_jar and dio_cookie_manager package and to use the cookie you need to store the cookie in fileStorage and to store, you need the documentsDirectory so you need the path provider package.
after adding these packages you can use the WebService class to inject the cookie to network package like dio.
and you can write your rest methods (get, post,….) inside the WebService as follows.
}
Before using the WebService class you must inject it as follows.
I am using provider package for injecting.
Using: