ToneSnap_FSX_Flutter/lib/data/storage/hive_storage.dart
fengshengxiong 422a3f8802 first commit
2024-06-11 11:53:38 +08:00

27 lines
668 B
Dart

// Author: fengshengxiong
// Date: 2024/5/8
// Description: 持久化储存
import 'package:hive_flutter/hive_flutter.dart';
import 'package:tone_snap/data/models/voice_model.dart';
const myVoiceBox = 'myVoiceBox';
const favoriteBox = 'favoriteBox';
Future initHive() async {
// 初始化
await Hive.initFlutter();
// 注册类型适配器
Hive.registerAdapter(VoiceModelAdapter());
// 打开盒子
await Hive.openBox<VoiceModel>(myVoiceBox);
await Hive.openBox<VoiceModel>(favoriteBox);
}
Box<VoiceModel> getMyVoiceBox() {
return Hive.box<VoiceModel>(myVoiceBox);
}
Box<VoiceModel> getFavoriteBox() {
return Hive.box<VoiceModel>(favoriteBox);
}