Tuesday, January 26, 2021

Shared Preferences || Flutter


Shared Preferences with Flutter
Shared Preferences is one of the ways to do it. It provides a way of reading and storing such data in a key-value pair.

What is Shared Preferences?
When you're working on some client apps, you'll often come across situations, where you need to store some data in the persistent storage of devices. For example, let's say you're using some OAuth client for one of your login methods, for that you'll need to store the access token on the client's device so that the client does not have to sign in again on relaunching the app.

Adding shared_preferences in pubspec.yaml

https://pub.dev/packages/shared_preferences/install
shared_preferences: ^0.5.12+4

Please set your constraint to shared_preferences: '>=0.5.y+x <2.0.0'

In our main.dart file, Let's convert our main function to async
void main() async{
  runApp(myApp);
  await StorageService.createInstance();
}

Happy Coding :)
.................................................................................................................................................................................................................................
Example :#1




Happy Coding :)
.................................................................................................................................................................................................................................
Example :#2




Happy Coding :)

No comments:

Post a Comment