1+ import 'package:cached_network_image_ce/cached_network_image.dart' ;
12import 'package:flutter/material.dart' ;
23import 'package:flutter_it/flutter_it.dart' ;
34
@@ -58,12 +59,6 @@ class SafeNetworkImage extends StatelessWidget with WatchItMixin {
5859 Icon (Iconz .musicNote, size: height != null ? height! * 0.7 : null ),
5960 );
6061
61- if (url == null ||
62- url! .isEmpty ||
63- _failedUrls.contains (url! ) ||
64- (Uri .tryParse (url! )? .host.isEmpty ?? false ))
65- return fallBack;
66-
6762 final errorWidget = Center (
6863 child:
6964 this .errorWidget ??
@@ -74,29 +69,35 @@ class SafeNetworkImage extends StatelessWidget with WatchItMixin {
7469 ),
7570 );
7671
77- return Image .network (
78- url! ,
72+ if (url == null ||
73+ url! .isEmpty ||
74+ _failedUrls.contains (url! ) ||
75+ (Uri .tryParse (url! )? .host.isEmpty ?? false ))
76+ return errorWidget;
77+
78+ return CachedNetworkImage (
79+ cacheManager: _cacheManager,
80+ imageUrl: url! ,
7981 height: height,
8082 width: width,
81- cacheHeight: cacheHeight,
82- cacheWidth: cacheWidth,
83+ memCacheHeight: cacheHeight,
84+ memCacheWidth: cacheWidth,
85+ maxWidthDiskCache: cacheWidth,
86+ maxHeightDiskCache: cacheHeight,
8387 fit: fit,
8488 filterQuality: filterQuality,
85- headers: httpHeaders,
86- frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
87- if (frame != null ) {
88- onImageLoaded? .call (NetworkImage (url! ));
89- }
90- if (wasSynchronouslyLoaded) {
91- return child;
92- }
93- return AnimatedOpacity (
94- opacity: frame == null ? 0 : 1 ,
95- duration: const Duration (milliseconds: 300 ),
96- curve: Curves .easeInOut,
97- child: child,
89+ httpHeaders: httpHeaders,
90+ imageBuilder: (context, imageProvider) {
91+ onImageLoaded? .call (imageProvider);
92+ return Image (
93+ image: imageProvider,
94+ height: height,
95+ width: width,
96+ fit: fit,
97+ filterQuality: filterQuality,
9898 );
9999 },
100+ placeholder: (context, url) => fallbackWidget ?? fallBack,
100101 errorBuilder: (context, error, _) {
101102 final message = switch (error.runtimeType) {
102103 final NetworkImageLoadException e => switch (e.statusCode) {
@@ -121,3 +122,12 @@ class SafeNetworkImage extends StatelessWidget with WatchItMixin {
121122 );
122123 }
123124}
125+
126+ final _cacheManager = DefaultCacheManager (
127+ stalePeriod: const Duration (days: 1 ),
128+ maxNrOfCacheObjects: 100 ,
129+ connectionParameters: ConnectionParameters (
130+ connectionTimeout: const Duration (seconds: 10 ),
131+ requestTimeout: const Duration (seconds: 30 ),
132+ ),
133+ );
0 commit comments