KonectarApp/lib/viewmodel/hive_repository.dart

29 lines
847 B
Dart
Raw 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');
hiveApiConstantsBox.addAll(hiveList);
}
static Future<bool> checkIfApiExists(
String api,
) async {
late Box<HiveApiConstants> hiveApiConstantsBox;
hiveApiConstantsBox =
await Hive.openBox<HiveApiConstants>('hiveApiConstants');
List<HiveApiConstants> list = hiveApiConstantsBox.values.toList();
return list.indexWhere(
(element) => element.functionName == api,
) ==
-1
? false
: true;
}
}