fromMap static method

URLRequest? fromMap(
  1. Map<String, dynamic>? map, {
  2. EnumMethod? enumMethod,
})

Gets a possible URLRequest instance from a Map value.

Implementation

static URLRequest? fromMap(
  Map<String, dynamic>? map, {
  EnumMethod? enumMethod,
}) {
  if (map == null) {
    return null;
  }
  final instance = URLRequest(
    allowsCellularAccess: map['allowsCellularAccess'],
    allowsConstrainedNetworkAccess: map['allowsConstrainedNetworkAccess'],
    allowsExpensiveNetworkAccess: map['allowsExpensiveNetworkAccess'],
    assumesHTTP3Capable: map['assumesHTTP3Capable'],
    attribution: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => URLRequestAttribution.fromNativeValue(
        map['attribution'],
      ),
      EnumMethod.value => URLRequestAttribution.fromValue(map['attribution']),
      EnumMethod.name => URLRequestAttribution.byName(map['attribution']),
    },
    body: map['body'] != null
        ? Uint8List.fromList(map['body'].cast<int>())
        : null,
    cachePolicy: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => URLRequestCachePolicy.fromNativeValue(
        map['cachePolicy'],
      ),
      EnumMethod.value => URLRequestCachePolicy.fromValue(map['cachePolicy']),
      EnumMethod.name => URLRequestCachePolicy.byName(map['cachePolicy']),
    },
    headers: map['headers']?.cast<String, String>(),
    httpShouldHandleCookies: map['httpShouldHandleCookies'],
    httpShouldUsePipelining: map['httpShouldUsePipelining'],
    iosAllowsCellularAccess: map['allowsCellularAccess'],
    iosAllowsConstrainedNetworkAccess: map['allowsConstrainedNetworkAccess'],
    iosAllowsExpensiveNetworkAccess: map['allowsExpensiveNetworkAccess'],
    iosCachePolicy: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => IOSURLRequestCachePolicy.fromNativeValue(
        map['cachePolicy'],
      ),
      EnumMethod.value => IOSURLRequestCachePolicy.fromValue(
        map['cachePolicy'],
      ),
      EnumMethod.name => IOSURLRequestCachePolicy.byName(map['cachePolicy']),
    },
    iosHttpShouldHandleCookies: map['httpShouldHandleCookies'],
    iosHttpShouldUsePipelining: map['httpShouldUsePipelining'],
    iosMainDocumentURL: map['mainDocumentURL'] != null
        ? Uri.tryParse(map['mainDocumentURL'])
        : null,
    iosNetworkServiceType: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue =>
        IOSURLRequestNetworkServiceType.fromNativeValue(
          map['networkServiceType'],
        ),
      EnumMethod.value => IOSURLRequestNetworkServiceType.fromValue(
        map['networkServiceType'],
      ),
      EnumMethod.name => IOSURLRequestNetworkServiceType.byName(
        map['networkServiceType'],
      ),
    },
    iosTimeoutInterval: map['timeoutInterval'],
    mainDocumentURL: map['mainDocumentURL'] != null
        ? WebUri(map['mainDocumentURL'])
        : null,
    method: map['method'],
    networkServiceType: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => URLRequestNetworkServiceType.fromNativeValue(
        map['networkServiceType'],
      ),
      EnumMethod.value => URLRequestNetworkServiceType.fromValue(
        map['networkServiceType'],
      ),
      EnumMethod.name => URLRequestNetworkServiceType.byName(
        map['networkServiceType'],
      ),
    },
    timeoutInterval: map['timeoutInterval'],
    url: map['url'] != null ? WebUri(map['url']) : null,
  );
  return instance;
}