fromJson static method

FileUploadConfig? fromJson(
  1. dynamic value
)

Returns a new FileUploadConfig instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static FileUploadConfig? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'allowed_file_extensions'),
          'Required key "FileUploadConfig[allowed_file_extensions]" is missing from JSON.');
      assert(json[r'allowed_file_extensions'] != null,
          'Required key "FileUploadConfig[allowed_file_extensions]" has a null value in JSON.');
      assert(json.containsKey(r'allowed_mime_types'),
          'Required key "FileUploadConfig[allowed_mime_types]" is missing from JSON.');
      assert(json[r'allowed_mime_types'] != null,
          'Required key "FileUploadConfig[allowed_mime_types]" has a null value in JSON.');
      assert(json.containsKey(r'blocked_file_extensions'),
          'Required key "FileUploadConfig[blocked_file_extensions]" is missing from JSON.');
      assert(json[r'blocked_file_extensions'] != null,
          'Required key "FileUploadConfig[blocked_file_extensions]" has a null value in JSON.');
      assert(json.containsKey(r'blocked_mime_types'),
          'Required key "FileUploadConfig[blocked_mime_types]" is missing from JSON.');
      assert(json[r'blocked_mime_types'] != null,
          'Required key "FileUploadConfig[blocked_mime_types]" has a null value in JSON.');
      assert(json.containsKey(r'size_limit'),
          'Required key "FileUploadConfig[size_limit]" is missing from JSON.');
      assert(json[r'size_limit'] != null,
          'Required key "FileUploadConfig[size_limit]" has a null value in JSON.');
      return true;
    }());

    return FileUploadConfig(
      allowedFileExtensions: json[r'allowed_file_extensions'] is Iterable
          ? (json[r'allowed_file_extensions'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      allowedMimeTypes: json[r'allowed_mime_types'] is Iterable
          ? (json[r'allowed_mime_types'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      blockedFileExtensions: json[r'blocked_file_extensions'] is Iterable
          ? (json[r'blocked_file_extensions'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      blockedMimeTypes: json[r'blocked_mime_types'] is Iterable
          ? (json[r'blocked_mime_types'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      sizeLimit: mapValueOfType<int>(json, r'size_limit')!,
    );
  }
  return null;
}