[英]how to read and write the FlutterSecureStorage in public package in flutter
Because many of my apps would use FlutterSecureStorage
, so I define the FlutterSecureStorage
in a public lib like this:因为我的许多应用程序都会使用FlutterSecureStorage
,所以我在公共库中定义了FlutterSecureStorage
,如下所示:
bool isLoggedIn = false;
String baseUrl = "";
String shareUrl = "";
String staticResourceUrl = "";
final pageStorageBucket = PageStorageBucket();
final storage = new FlutterSecureStorage();
enum ConfigType { DEV, PRO }
class GlobalConfig {}
I could expose the GlobalConfig in main.dart like this in public lib:我可以在公共库中像这样公开 main.dart 中的 GlobalConfig:
export 'src/config/global_config.dart';
but I just wanna to know how to use the storage
after import the public lib in my app, I am using the public lib in my app like this:但我只想知道在我的应用程序中导入公共库后如何使用storage
,我在我的应用程序中使用公共库,如下所示:
wheel:
git:
url: https://github.com/jiangxiaoqiang/wheel.git
ref: main
how to read and write global FlutterSecureStorage
when add dependencies of wheel lib?添加wheel lib的依赖项时如何读写全局FlutterSecureStorage
? is it possible?可能吗? or define the FlutterSecureStorage
in each app is the best practice?还是在每个应用程序中定义FlutterSecureStorage
是最佳实践? or what should I do use the FlutterSecureStorage
global?或者我应该如何使用FlutterSecureStorage
全局?
I define a secure storage util class:我定义了一个安全存储工具 class:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class SecureStorageUtil{
static FlutterSecureStorage _preferences = FlutterSecureStorage();
static Future<String?> getString (String key, {String defValue = ''}) {
return _preferences.read(key:key) ;
}
static Future<void> putString(String key, String value) {
return _preferences.write(key:key, value:value);
}
}
use it like this:像这样使用它:
SecureStorageUtil.putString("token", "1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.