didvan-app/lib/services/storage/storage.dart

44 lines
1.1 KiB
Dart

import 'package:hive/hive.dart';
class StorageService {
static late final String appDocsDir;
static late final String appTempsDir;
static Future<void> setValue({
required String key,
required dynamic value,
required String boxName,
}) async {
final Box box = await Hive.openBox(boxName);
await box.put(key, value);
await box.close();
}
static Future getValue({required String key, required String boxName}) async {
final Box box = await Hive.openBox(boxName);
final value = await box.get(key);
await box.close();
return value;
}
static Future<void> setBoxData({
required Map data,
required String boxName,
}) async {
final Box box = await Hive.openBox(boxName);
await box.putAll(data);
await box.close();
}
static Future<Map> getBoxData({required String boxName}) async {
final Box box = await Hive.openBox(boxName);
await box.close();
return box.toMap();
}
static Future<bool> boxExists({required String boxName}) async {
final bool result = await Hive.boxExists(boxName);
return result;
}
}