fluttercandies / extended_image

A powerful official extension library of image, which support placeholder(loading)/ failed state, cache network, zoom pan image, photo view, slide out page, editor(crop,rotate,flip), paint custom etc.
https://fluttercandies.github.io/extended_image/
MIT License
1.94k stars 505 forks source link

[Feature request] pluggable data loading http2/http3 #678

Closed SbiCA closed 5 months ago

SbiCA commented 6 months ago

Platforms

dart, Android, iOS, Web, Linux

Description

I'd like to make use of http2/http3 for image loading using dio or my own http.client.

Atm. it seems that the package is using a static instance of http.client and doesn't allow to provide my own instance.


abstract class ImageDataLoader {
      ///get network image data from cached
  Future<Uint8List?> getNetworkImageData({   String url, {
    double scale,
    Map<String, String>? headers});
}

code

I'd like to use Dio to load the bytes since it supports h2 instead of the static http.client instance


  final dio = Dio()
    ..options.baseUrl = 'https://pub.dev'
    ..interceptors.add(LogInterceptor())
    ..httpClientAdapter = Http2Adapter(
      ConnectionManager(idleTimeout: Duration(seconds: 10)),
    );

  Response<String> response;
  response = await dio.get('/?xx=6');
  for (final e in response.redirects) {
    print('redirect: ${e.statusCode} ${e.location}');
  }

see https://github.com/cfug/dio/tree/main/plugins/http2_adapter for more details on how the adapter works.

Why

zmtzawqlp commented 6 months ago

Maybe you can create your own provider and implements it base on ExtendedNetworkImageProvider

SbiCA commented 6 months ago

@zmtzawqlp I could give a try, if this is worth a PR? and you think it's for the benefit of everyone. just a word of warning I'm not a dart expert šŸ˜…

zmtzawqlp commented 6 months ago

@zmtzawqlp I could give a try, if this is worth a PR? and you think it's for the benefit of everyone. just a word of warning I'm not a dart expert šŸ˜…

i think we should keep the library simple, and only use flutter official API.