get_secure_storage
get_storage 的安全版本,這是一個用 Dart 完全撰寫的快速、輕量且同步的鍵值儲存
get_storage 的安全版本,這是一個用 Dart 完全撰寫的快速、輕量且同步的鍵值儲存
{"sdk":"flutter"}>=4.0.0 <6.0.0^2.1.2^2.7.0^2.0.1{"sdk":"flutter"}以下為英文專案原文快照,最新內容請造訪 GitHub。
A cryptography Secure version of GetStorage originally written by Jonny Borges (https://github.com/jonataslaw/get_storage).
GetSecureStorage is a secure, fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and is based on the Cryptography dart package.
The cryptography library used is https://pub.dev/packages/cryptography
The algorithm used is 128bit AES-CTR with MAC sha256
Supports Android, iOS, Web, Mac, Linux, and Windows. Can store String, int, double, Map and List
dependencies:
get_secure_storage:
You can install packages from the command line:
with Flutter:
$ flutter packages get
Now in your Dart code, you can use:
import 'package:get_secure_storage/get_secure_storage.dart';
main() async {
await GetSecureStorage.init(password: 'strongpassword');
runApp(App());
}
GetSecureStorage().read('key')final box = GetSecureStorage(password: 'strongpassword');
write :box.write('quote', 'GetSecureStorage is the best');
read:print(box.read('quote'));
// out: GetSecureStorage is the best
remove:box.remove('quote');
listen:Function? disposeListen;
disposeListen = box.listen((){
print('box changed');
});
disposeListen?.call();
listenKey:box.listenKey('key', (value){
print('new key is $value');
});
box.erase();
GetSecureStorage g = GetSecureStorage(container:'MyStorage', password: 'strongpassword');
await GetSecureStorage.init(container:'MyStorage', password: 'strongpassword');
class MyPref {
static final _otherBox = () => GetSecureStorage(container:'MyPref', password: 'strongpassword');
final username = ''.val('username');
final age = 0.val('age');
final price = 1000.val('price', getBox: _otherBox);
// or
final username2 = ReadWriteValue('username', '');
final age2 = ReadWriteValue('age', 0);
final price2 = ReadWriteValue('price', '', _otherBox);
}
...
void updateAge() {
final age = 0.val('age');
// or
final age = ReadWriteValue('age', 0, () => box);
// or
final age = Get.find<MyPref>().age;
age.val = 1; // will save to box
final realAge = age.val; // will read from box
}