toSynced method

Future<SyncedVendorDictionary<V>> toSynced({
  1. Comparator<DictionaryEntry<V>>? sortEntries,
})

Obtain UnmodifiableMapBase, synced VendorDictionary with exact same key-value pair stored in this dictionary.

By default, it should be returned unsorted Map based SyncedVendorDictionary. To enable sorting order of Map, sortEntries should be defined, unless it called during testing which will be sorted by VendorDictionary.keys.

Implementation

Future<SyncedVendorDictionary<V>> toSynced(
    {Comparator<DictionaryEntry<V>>? sortEntries}) async {
  final List<DictionaryEntry<V>> syncedEntries = await entries.toList();
  late final Map<String, V> syncedMap;

  if (sortEntries != null ||
      Platform.environment.containsKey("FLUTTER_TEST")) {
    syncedEntries.sort(sortEntries ?? _keySort);
    syncedMap = LinkedHashMap();
  } else {
    syncedMap = HashMap();
  }

  syncedMap.addEntries(syncedEntries);

  return SyncedVendorDictionary._(syncedMap, syncedEntries.length);
}