Flutter development – data persistent storage shared_preferences
An overview shared_preferences,It saves data in the form of Key-Value(key-value pair),supports Android and iOS shared_preferences is a third-party plug-in , use SharedPreferences in Android , use NSUserDefaults Second add dependency 2.1 Dependency address pub address:https://pub.flutter-io. cn/packages/shared_preferences Github address :https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences 2.2 Add dependencies Add dependencies in the pubspec.yaml file of the project dependencies:shared_preferences: ^2.0.6 Execute command flutter pub get Three shared_preferences operations 3.1 Supported data types The data types supported by shared_preferences are int, double, bool, string, stringList 3.2 shared_preferences instantiation Synchronous operation Future _prefs = SharedPreferences.getInstance(); Asynchronous operation (async) var prefs = await SharedPreferences.getInstance(); 3.3 Basic operation of data (int as an example) 3.3.1 Read Data Future _readData() async {var prefs = await SharedPreferences.getInstance();var result = ; prefs.getInt('Key_Int'); return result ?? 0;} 3.3.2 Save data _saveData() async {var prefs = await SharedPreferences.getInstance();prefs.setInt('Key_Int', 12);} 3.3.3 Delete data Future _deleteData() async {var prefs = await SharedPreferences.getInstance();prefs .remove('Key');} 3.3.4 Clear all data Future _clearData() async {var prefs = await SharedPreferences.getInstance();prefs.clear();} 3.4 Key related operations 3.4.1 Get all Keys Future<Set> _getKeys() async {var prefs = await SharedPreferences .getInstance();var keys = prefs.getKeys();return keys ?? [];} 3.4.2 Check whether Does the Key exist Future _containsKey() async {var prefs = await SharedPreferences.getInstance();return prefs.containsKey('Key') ? ? false;} Four…