fromJson<T> static method

Set<T>? fromJson<T>(
  1. dynamic value, {
  2. required T itemFromJson(
    1. dynamic
    ),
})

Returns a deserialized version of the Set.

Implementation

static Set<T>? fromJson<T>(
  dynamic value, {
  required T Function(dynamic) itemFromJson,
}) {
  if (value is Set<T>) return value;

  var set = (value as List?)?.map(itemFromJson).toSet();

  if (set != null && value!.length != set.length) {
    throw Exception(
        'Input list for Set contained duplicate items. List with length ${value.length} resulted in a set with only ${set.length} item(s).');
  }

  return set;
}