54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
import 'package:pwa_ios/model/interaction_config_data.dart';
|
|
|
|
class HiveDataRepository extends ChangeNotifier {
|
|
Box<InteractionConfigData> _hiveBox; // Use the correct type for your Hive box
|
|
|
|
HiveDataRepository(this._hiveBox);
|
|
|
|
List<InteractionConfigData> getAllDataFromHive() {
|
|
print("Stored_ALL_valuesssss : ${_hiveBox.values.toList()}");
|
|
print(
|
|
"Stored_ALL_valuesssss_leangthhh : ${_hiveBox.values.toList().length}");
|
|
|
|
return _hiveBox.values.toList();
|
|
}
|
|
|
|
Future<void> openHiveBox() async {
|
|
_hiveBox =
|
|
await Hive.openBox<InteractionConfigData>('InteractionConfigDataBox');
|
|
}
|
|
|
|
Future<void> closeHiveBox() async {
|
|
_hiveBox.close();
|
|
}
|
|
|
|
List<InteractionConfigData> getAllofflineData() {
|
|
return _hiveBox.values.toList();
|
|
}
|
|
|
|
Future<void> addOfflineData(InteractionConfigData data, int id) async {
|
|
// _hiveBox = await Hive.openBox('InteractionDataBox');
|
|
|
|
await _hiveBox.put(id, data);
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<int> getNextAutoIncrementValue() async {
|
|
var counterBox = await Hive.openBox<int>('counterBox');
|
|
if (!counterBox.containsKey('counter')) {
|
|
counterBox.put('counter', 0);
|
|
}
|
|
|
|
int? counter = counterBox.get('counter');
|
|
counterBox.put('counter', counter! + 1);
|
|
|
|
await counterBox.close();
|
|
|
|
return counter;
|
|
}
|
|
}
|