@@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart';
10
10
import 'package:http_client_helper/http_client_helper.dart' ;
11
11
import 'package:path/path.dart' ;
12
12
import 'package:path_provider/path_provider.dart' ;
13
+ import 'package:rhttp/rhttp.dart' ;
13
14
14
15
import '../utils/extension/extension.dart' ;
15
16
import '../utils/logger.dart' ;
@@ -548,22 +549,42 @@ class MixinNetworkImageProvider
548
549
) async {
549
550
try {
550
551
final resolved = Uri .base .resolve (key.url);
551
- final response = await _tryGetResponse (resolved, key.proxyConfig);
552
- if (response == null || response.statusCode != HttpStatus .ok) {
553
- return null ;
552
+ final Uint8List bytes;
553
+
554
+ if (key.proxyConfig != null ) {
555
+ final response = await _tryGetResponse (resolved, key.proxyConfig);
556
+ if (response == null || response.statusCode != HttpStatus .ok) {
557
+ return null ;
558
+ }
559
+
560
+ bytes = await consolidateHttpClientResponseBytes (
561
+ response,
562
+ onBytesReceived: chunkEvents != null
563
+ ? (int cumulative, int ? total) {
564
+ chunkEvents.add (ImageChunkEvent (
565
+ cumulativeBytesLoaded: cumulative,
566
+ expectedTotalBytes: total,
567
+ ));
568
+ }
569
+ : null ,
570
+ );
571
+ } else {
572
+ d ('no proxy: load image from network: $resolved ' );
573
+ final response = await Rhttp .getBytes (resolved.toString (),
574
+ onReceiveProgress: chunkEvents != null
575
+ ? (int cumulative, int total) {
576
+ chunkEvents.add (ImageChunkEvent (
577
+ cumulativeBytesLoaded: cumulative,
578
+ expectedTotalBytes: total,
579
+ ));
580
+ }
581
+ : null );
582
+ if (response.statusCode != HttpStatus .ok) {
583
+ return null ;
584
+ }
585
+ bytes = response.body;
554
586
}
555
587
556
- final bytes = await consolidateHttpClientResponseBytes (
557
- response,
558
- onBytesReceived: chunkEvents != null
559
- ? (int cumulative, int ? total) {
560
- chunkEvents.add (ImageChunkEvent (
561
- cumulativeBytesLoaded: cumulative,
562
- expectedTotalBytes: total,
563
- ));
564
- }
565
- : null ,
566
- );
567
588
if (bytes.lengthInBytes == 0 ) {
568
589
return Future <Uint8List >.error (
569
590
StateError ('NetworkImage is an empty file: $resolved ' ));
0 commit comments