KonectarApp/lib/viewmodel/hive_repository.dart

31 lines
1006 B
Dart
Raw Permalink Normal View History

2024-12-10 09:36:43 +00:00
import 'package:hive_flutter/hive_flutter.dart';
import 'package:konectar_events/model/hive_api_constants.dart';
class HiveOperations {
static Future<void> saveApiConstants(List<HiveApiConstants> hiveList) async {
late Box<HiveApiConstants> hiveApiConstantsBox;
hiveApiConstantsBox =
await Hive.openBox<HiveApiConstants>('hiveApiConstants');
2024-12-19 05:21:33 +00:00
print("DataAffing");
// hiveApiConstantsBox.clear();
2024-12-10 09:36:43 +00:00
hiveApiConstantsBox.addAll(hiveList);
}
2024-12-16 11:26:32 +00:00
static Future<bool> checkIfApiExists(String api, String moduleName) async {
2024-12-10 09:36:43 +00:00
late Box<HiveApiConstants> hiveApiConstantsBox;
hiveApiConstantsBox =
await Hive.openBox<HiveApiConstants>('hiveApiConstants');
List<HiveApiConstants> list = hiveApiConstantsBox.values.toList();
2024-12-19 05:21:33 +00:00
print("Show/HideApiList: $list");
2024-12-10 09:36:43 +00:00
return list.indexWhere(
2024-12-16 11:26:32 +00:00
(element) =>
element.functionName == api && element.module == moduleName,
2024-12-10 09:36:43 +00:00
) ==
-1
? false
: true;
}
}