因此,我创建了一个更简单的抽象层次,将hive应用到我的flatter应用程序中。这应该是管理和访问所有配置单元框的中心点。由于在测试期间getapplicationdocumentsdirectory不可用,我如何仍然能够测试整个文件?
import 'package:boulder_fit/services/workout.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path_rovider;
import 'workout.dart';
class HiveService {
static final HiveService _singleton = HiveService._internal();
static const String _workoutBox = "workoutBox";
factory HiveService() {
return _singleton;
}
HiveService._internal();
static Future<void> init() async {
final appDocumentDirectory =
await path_rovider.getApplicationDocumentsDirectory();
Hive.init(appDocumentDirectory.path);
Hive.registerAdapter(WorkoutAdapter());
}
static Future openWorkouts() {
return Hive.openBox<Workout>(_workoutBox);
}
static Future close() {
return Hive.close();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!