mirror of
https://github.com/foss42/apidash.git
synced 2025-06-04 01:13:30 +08:00
Adding Hive persistence
This commit is contained in:
31
lib/services/hive_services.dart
Normal file
31
lib/services/hive_services.dart
Normal file
@ -0,0 +1,31 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
// constants
|
||||
const String kDataBox = "data";
|
||||
|
||||
// sequence of ids
|
||||
const String kDataBoxIds = "ids";
|
||||
|
||||
Future<void> openBoxes() async {
|
||||
await Hive.initFlutter();
|
||||
await Hive.openBox(kDataBox);
|
||||
}
|
||||
|
||||
class HiveHandler {
|
||||
late final Box dataBox;
|
||||
|
||||
HiveHandler() {
|
||||
dataBox = Hive.box(kDataBox);
|
||||
}
|
||||
|
||||
List<String>? getIds() => dataBox.get(kDataBoxIds) as List<String>?;
|
||||
Future<void> setIds(List<String>? ids) => dataBox.put(kDataBoxIds, ids);
|
||||
|
||||
Map<String, dynamic>? getRequestModel(String id) =>
|
||||
dataBox.get(id) as Map<String, dynamic>?;
|
||||
Future<void> setRequestModel(
|
||||
String id, Map<String, dynamic>? requestModelJson) =>
|
||||
dataBox.put(id, requestModelJson);
|
||||
|
||||
Future<int> clear() => dataBox.clear();
|
||||
}
|
Reference in New Issue
Block a user