- 简单的,异步的,持久化的key-value存储系统;
- 在Android上它是基于
SharedPreferences
的; - 在iOS上它是基于
NSUserDefaults
的;
dependencies: shared_preferences: ^0.5.1+
import 'package:shared_preferences/shared_preferences.dart';
存储数据
final prefs = await SharedPreferences.getInstance();
// set value
prefs.setInt('counter', counter);
读取数据
final prefs = await SharedPreferences.getInstance();
// Try reading data from the counter key. If it does not exist, return 0.
final counter = prefs.getInt('counter') ?? 0;}
删除数据
final prefs = await SharedPreferences.getInstance();
prefs.remove('counter');
存储相关
读取相关