Skip to content

_network_image_io.dart #2

@ayzek67

Description

@ayzek67

Hi
I could not solve the error, I would be very happy if you help me.

'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 25 pos 11: 'url != null': is not true.

/// The dart:io implementation of [image_provider.NetworkImage].
@immutable
class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkImage> implements image_provider.NetworkImage {
/// Creates an object that fetches the image at the given URL.
///
/// The arguments [url] and [scale] must not be null.
const NetworkImage(this.url, { this.scale = 1.0, this.headers })
:assert(url != null ),
assert(scale != null);

@OverRide
final String url;

@OverRide
final double scale;

@OverRide
final Map<String, String>? headers;

@OverRide
Future obtainKey(image_provider.ImageConfiguration configuration) {
return SynchronousFuture(this);
}

@OverRide
ImageStreamCompleter load(image_provider.NetworkImage key, image_provider.DecoderCallback decode) {
// Ownership of this controller is handed off to [_loadAsync]; it is that
// method's responsibility to close the controller's stream when the image
// has been loaded or an error is thrown.
final StreamController chunkEvents = StreamController();

return MultiFrameImageStreamCompleter(
  codec: _loadAsync(key as NetworkImage, chunkEvents, decode),
  chunkEvents: chunkEvents.stream,
  scale: key.scale,
  debugLabel: key.url,
  informationCollector: () {
    return <DiagnosticsNode>[
      DiagnosticsProperty<image_provider.ImageProvider>('Image provider', this),
      DiagnosticsProperty<image_provider.NetworkImage>('Image key', key),
    ];
  },
);

}

// Do not access this field directly; use [_httpClient] instead.
// We set autoUncompress to false to ensure that we can trust the value of
// the Content-Length HTTP header. We automatically uncompress the content
// in our call to [consolidateHttpClientResponseBytes].
static final HttpClient _sharedHttpClient = HttpClient()..autoUncompress = false;

static HttpClient get _httpClient {
HttpClient client = _sharedHttpClient;
assert(() {
if (debugNetworkImageHttpClientProvider != null)
client = debugNetworkImageHttpClientProvider!();
return true;
}());
return client;
}

Future<ui.Codec> _loadAsync(
NetworkImage key,
StreamController chunkEvents,
image_provider.DecoderCallback decode,
) async {
try {
assert(key == this);

  final Uri resolved = Uri.base.resolve(key.url);

  final HttpClientRequest request = await _httpClient.getUrl(resolved);

  headers?.forEach((String name, String value) {
    request.headers.add(name, value);
  });
  final HttpClientResponse response = await request.close();
  if (response.statusCode != HttpStatus.ok) {
    // The network may be only temporarily unavailable, or the file will be
    // added on the server later. Avoid having future calls to resolve
    // fail to check the network again.
    await response.drain<List<int>>();
    throw image_provider.NetworkImageLoadException(statusCode: response.statusCode, uri: resolved);
  }

  final Uint8List bytes = await consolidateHttpClientResponseBytes(
    response,
    onBytesReceived: (int cumulative, int? total) {
      chunkEvents.add(ImageChunkEvent(
        cumulativeBytesLoaded: cumulative,
        expectedTotalBytes: total,
      ));
    },
  );
  if (bytes.lengthInBytes == 0)
    throw Exception('NetworkImage is an empty file: $resolved');

  return decode(bytes);
} catch (e) {
  // Depending on where the exception was thrown, the image cache may not
  // have had a chance to track the key in the cache at all.
  // Schedule a microtask to give the cache a chance to add the key.
  scheduleMicrotask(() {
    PaintingBinding.instance!.imageCache!.evict(key);
  });
  rethrow;
} finally {
  chunkEvents.close();
}

}

@OverRide
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
return false;
return other is NetworkImage
&& other.url == url
&& other.scale == scale;
}

@OverRide
int get hashCode => ui.hashValues(url, scale);

@OverRide
String toString() => '${objectRuntimeType(this, 'NetworkImage')}("$url", scale: $scale)';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions