saveGeneral method

Future<int> saveGeneral({
  1. required Object object,
  2. int? key,
  3. String? pw,
})

All of the above has been for FHIR resources and data, below is if you need to store whatever else as well


Implementation

Future<int> saveGeneral({
  required Object object,
  int? key,
  String? pw,
}) async {
  await _ensureInit(pw: pw);
  final HiveAesCipher? cipher = cipherFromKey(key: pw);
  try {
    final Box<Object> box;
    if (!Hive.isBoxOpen('general')) {
      box = await Hive.openBox('general', encryptionCipher: cipher);
    } else {
      box = Hive.box('general');
    }
    if (key == null) {
      return box.add(object);
    } else {
      await box.put(key, object);
      return key;
    }
  } catch (e) {
    return -1;
  }
}