Reputation: 2405
I am currently build an app that use SharedPreferences
to save my data, but as I know, I have to use Shared preferences for Android and NSUserDefaults for iOS, is there a way or condition so that I can use both of them (Shared preferences and NSUserDefaults) inside my app... so my app can be used for android and iOS when saving the data
Upvotes: 1
Views: 2932
Reputation: 9734
Install the SharedPreferences package for storing app preference simple data into your app.
Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data. Data is persisted to disk asynchronously. Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data.
Storing:
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('name', 'Bob');
Retrieving:
SharedPreferences prefs = await SharedPreferences.getInstance();
final name = prefs.getString('name');
You can store and retrieve int, string, bool, double, etc. For more info, check out this documentation.
Upvotes: 1