// Author: fengshengxiong // Date: 2024/5/8 // Description: 收藏数据 import 'package:tone_snap/data/models/voice_model.dart'; import 'package:tone_snap/data/storage/hive_storage.dart'; class MyVoiceData { /// 私有构造函数 MyVoiceData._(); /// 静态常量用于保存类的唯一实例 static final MyVoiceData _instance = MyVoiceData._(); /// 工厂构造函数返回类的唯一实例 factory MyVoiceData() { return _instance; } /// 声明盒子 /// 注意, main函数中这个盒子已经打开, 可以进行存储操作 final _box = getMyVoiceBox(); /// 获取数据 List getList() { return _box.values.toList(); } /// 添加数据 Future addData(VoiceModel voiceModel) async { return await _box.add(voiceModel); } /// 删除 Future delete(index) async { await _box.deleteAt(index); await _box.flush(); } /// 清空所有数据 Future clear() async { await _box.clear(); await _box.flush(); } }