set method

Future<bool> set(
  1. String key,
  2. String value
)

Set value in storage

Implementation

Future<bool> set(String key, String value) async {
  try {
    final lib = PlatformLoader.load();
    final setFn = lib.lookupFunction<
        Int32 Function(Pointer<Utf8>, Pointer<Utf8>),
        int Function(Pointer<Utf8>, Pointer<Utf8>)>('rac_storage_set');

    final keyPtr = key.toNativeUtf8();
    final valuePtr = value.toNativeUtf8();
    try {
      final result = setFn(keyPtr, valuePtr);
      return result == RacResultCode.success;
    } finally {
      calloc.free(keyPtr);
      calloc.free(valuePtr);
    }
  } catch (e) {
    _logger.debug('rac_storage_set not available: $e');
    return false;
  }
}