MMKV constructor

MMKV(
  1. String mmapID, {
  2. MMKVMode mode = MMKVMode.SINGLE_PROCESS_MODE,
  3. String? cryptKey,
  4. String? rootDir,
  5. int expectedCapacity = 0,
})

Get an MMKV instance with an unique ID mmapID.

  • If you want a per-user mmkv, you could merge user-id within mmapID.
  • You can get a multi-process MMKV instance by passing MMKVMode.MULTI_PROCESS_MODE.
  • You can encrypt with cryptKey, which limits to 16 bytes at most.
  • You can customize the rootDir of the file.

Implementation

MMKV(String mmapID, {MMKVMode mode = MMKVMode.SINGLE_PROCESS_MODE, String? cryptKey, String? rootDir, int expectedCapacity = 0}) {
  if (mmapID.isNotEmpty) {
    final mmapIDPtr = _string2Pointer(mmapID);
    final cryptKeyPtr = _string2Pointer(cryptKey);
    final rootDirPtr = _string2Pointer(rootDir);

    _handle = _getMMKVWithID(mmapIDPtr, mode.index, cryptKeyPtr, rootDirPtr, expectedCapacity);

    calloc.free(mmapIDPtr);
    calloc.free(cryptKeyPtr);
    calloc.free(rootDirPtr);
  }
}