Translate-Flutter/lib/storage/hive_storage.dart
fengshengxiong 70d663706c 第一版
2024-07-12 11:26:44 +08:00

21 lines
514 B
Dart

// Author: fengshengxiong
// Date: 2024/5/8
// Description: 持久化储存
import 'package:hive_flutter/hive_flutter.dart';
import 'package:trans_lark/entity/history_model.dart';
const historyBox = 'historyBox';
Future initHive() async {
// 初始化
await Hive.initFlutter();
// 注册类型适配器
Hive.registerAdapter(HistoryEntityAdapter());
// 打开盒子
await Hive.openBox<HistoryEntity>(historyBox);
}
Box<HistoryEntity> getHistoryBox() {
return Hive.box<HistoryEntity>(historyBox);
}