赞
踩
import 'package:shared_preferences/shared_preferences.dart'; /// 数据存取工具类 /// 初始化:在main类中初始化: StorageUtils.getInstance(); /// 调用:StorageUtils.getString(ConstantUtils.userName); class StorageUtils { static late StorageUtils _instance; static late SharedPreferences _sharedPreferences; static Future<StorageUtils> getInstance() async { _instance = await StorageUtils._init().getSharedPreferences(); return _instance; } StorageUtils._init(); Future getSharedPreferences() async { _sharedPreferences = await SharedPreferences.getInstance(); } static saveInt(String key, int value) { _sharedPreferences.setInt(key, value); } static int getInt(String key, {int defaultVal = 0}) { return _sharedPreferences.getInt(key) ?? defaultVal; } static saveString(String key, String value) { _sharedPreferences.setString(key, value); } static String getString(String key, {String defaultVal =
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。