Skip to content

Commit

Permalink
add toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
laiiihz committed Sep 7, 2023
1 parent 519a6cb commit 44aaa14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/utils/hive_boxes/tool_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:alga/utils/hive_util.dart';
import 'package:hive/hive.dart';

class ToolConfig {
const ToolConfig(this.prefix);
final String prefix;
static Box get box => HiveUtil.favoriteBox;

Future write<T>(String name, T value) {
return box.put('${prefix}_$name', value);
}

T read<T>(String name, T defaultValue) {
return box.get('${prefix}_$name', defaultValue: defaultValue) as T;
}
}
2 changes: 2 additions & 0 deletions lib/utils/hive_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import 'package:hive_flutter/hive_flutter.dart';
class HiveUtil {
static late Box appConfigBox;
static late Box<String> favoriteBox;
static late Box<String> toolConfigBox;
static init() async {
await Hive.initFlutter('stored');
appConfigBox = await Hive.openBox('APP_CONFIG');
favoriteBox = await Hive.openBox<String>('FAVORITE');
toolConfigBox = await Hive.openBox('TOOL_CONFIG');
}
}

0 comments on commit 44aaa14

Please sign in to comment.