11import 'package:auto_size_text/auto_size_text.dart' ;
2+ import 'package:cached_network_image/cached_network_image.dart' ;
23import 'package:flutter/material.dart' ;
34import 'package:piwigo_ng/models/image_model.dart' ;
45import 'package:piwigo_ng/services/preferences_service.dart' ;
@@ -11,16 +12,12 @@ class ImageCard extends StatelessWidget {
1112 this .selected,
1213 required this .image,
1314 this .onLongPress,
14- this .example = false ,
15- this .derivative,
1615 }) : super (key: key);
1716
1817 final Function ()? onPressed;
1918 final Function ()? onLongPress;
2019 final bool ? selected;
21- final bool example;
2220 final ImageModel image;
23- final String ? derivative;
2421
2522 final Duration selectDuration = const Duration (milliseconds: 200 );
2623 final Curve selectCurve = Curves .easeInOut;
@@ -34,31 +31,49 @@ class ImageCard extends StatelessWidget {
3431 fit: StackFit .expand,
3532 children: [
3633 Builder (builder: (context) {
37- final String ? imageUrl = image.getDerivativeFromString (derivative ?? Preferences .getImageThumbnailSize)? .url;
38- if (example) {
39- return Image .asset (
40- imageUrl ?? '' ,
41- fit: BoxFit .cover,
42- errorBuilder: (context, o, s) {
43- debugPrint ("$o \n $s " );
44- return Center (child: Icon (Icons .image_not_supported));
45- },
46- );
47- }
48- return Image .network (
49- imageUrl ?? '' ,
50- fit: BoxFit .cover,
51- errorBuilder: (context, o, s) {
52- debugPrint ("$o \n $s " );
53- return Center (child: Icon (Icons .image_not_supported));
54- },
55- loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent ? loadingProgress) {
56- if (loadingProgress == null ) return child;
34+ final String ? imageUrl = image.getDerivativeFromString (Preferences .getImageThumbnailSize)? .url;
35+ return CachedNetworkImage (
36+ imageUrl: imageUrl ?? '' ,
37+ imageBuilder: (context, provider) => Hero (
38+ tag: "<hero image ${image .id }>" ,
39+ child: Image (
40+ image: provider,
41+ fit: BoxFit .cover,
42+ errorBuilder: (context, o, s) {
43+ debugPrint ("$o \n $s " );
44+ return FittedBox (
45+ fit: BoxFit .cover,
46+ child: Container (
47+ padding: const EdgeInsets .all (16.0 ),
48+ decoration: BoxDecoration (
49+ color: Theme .of (context).scaffoldBackgroundColor,
50+ ),
51+ child: const Icon (Icons .broken_image_outlined),
52+ ),
53+ );
54+ },
55+ ),
56+ ),
57+ progressIndicatorBuilder: (context, url, download) {
58+ if (download.downloaded >= (download.totalSize ?? 0 )) {
59+ return const SizedBox ();
60+ }
5761 return Center (
5862 child: CircularProgressIndicator (
59- value: loadingProgress.expectedTotalBytes != null
60- ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
61- : null ,
63+ value: download.progress,
64+ ),
65+ );
66+ },
67+ errorWidget: (context, url, error) {
68+ debugPrint ("[$url ] $error " );
69+ return FittedBox (
70+ fit: BoxFit .cover,
71+ child: Container (
72+ padding: const EdgeInsets .all (16.0 ),
73+ decoration: BoxDecoration (
74+ color: Theme .of (context).scaffoldBackgroundColor,
75+ ),
76+ child: const Icon (Icons .broken_image_outlined),
6277 ),
6378 );
6479 },
0 commit comments