encodeString method
Encode an utf-8 string.
expireDurationInSecond
override the default duration setting from enableAutoKeyExpire().
- Passing MMKV.ExpireNever (aka 0) will never expire.
Implementation
bool encodeString(String key, String? value, [int? expireDurationInSecond]) {
if (value == null) {
removeValue(key);
return true;
}
final keyPtr = key.toNativeUtf8();
final bytes = MMBuffer.fromList(const Utf8Encoder().convert(value))!;
final ret = (expireDurationInSecond == null)
? _encodeBytes(_handle, keyPtr, bytes.pointer!, bytes.length)
: _encodeBytesV2(_handle, keyPtr, bytes.pointer!, bytes.length, expireDurationInSecond);
calloc.free(keyPtr);
bytes.destroy();
return _int2Bool(ret);
}