WallPaper_FSX_Flutter/lib/common/storage/hive_storage.dart
2024-05-13 13:44:27 +08:00

22 lines
544 B
Dart

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