diff --git a/lib/utils/hive_boxes/tool_config.dart b/lib/utils/hive_boxes/tool_config.dart new file mode 100644 index 0000000..f6cb25e --- /dev/null +++ b/lib/utils/hive_boxes/tool_config.dart @@ -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(String name, T value) { + return box.put('${prefix}_$name', value); + } + + T read(String name, T defaultValue) { + return box.get('${prefix}_$name', defaultValue: defaultValue) as T; + } +} diff --git a/lib/utils/hive_util.dart b/lib/utils/hive_util.dart index a311653..db03043 100644 --- a/lib/utils/hive_util.dart +++ b/lib/utils/hive_util.dart @@ -3,9 +3,11 @@ import 'package:hive_flutter/hive_flutter.dart'; class HiveUtil { static late Box appConfigBox; static late Box favoriteBox; + static late Box toolConfigBox; static init() async { await Hive.initFlutter('stored'); appConfigBox = await Hive.openBox('APP_CONFIG'); favoriteBox = await Hive.openBox('FAVORITE'); + toolConfigBox = await Hive.openBox('TOOL_CONFIG'); } }