Skip to content

Commit c9058f9

Browse files
committed
Cached images thumbnails
Removed examples
1 parent 9ec4261 commit c9058f9

5 files changed

Lines changed: 57 additions & 159 deletions

File tree

lib/components/cards/album_card.dart

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ class AlbumCard extends StatelessWidget {
1414
required this.album,
1515
this.onTap,
1616
this.showActions = true,
17-
this.example = false,
1817
this.onDelete,
1918
this.onEdit,
2019
this.onMove,
2120
}) : super(key: key);
2221

23-
final bool example;
2422
final AlbumModel album;
2523
final Function()? onTap;
2624
final Function()? onDelete;
@@ -126,7 +124,6 @@ class AlbumCard extends StatelessWidget {
126124
),
127125
child: AlbumCardContent(
128126
album: album,
129-
example: example,
130127
),
131128
),
132129
),
@@ -151,7 +148,6 @@ class AlbumCard extends StatelessWidget {
151148
),
152149
child: AlbumCardContent(
153150
album: album,
154-
example: example,
155151
),
156152
),
157153
);
@@ -163,11 +159,9 @@ class AlbumCardContent extends StatelessWidget {
163159
const AlbumCardContent({
164160
Key? key,
165161
required this.album,
166-
this.example = false,
167162
}) : super(key: key);
168163

169164
final AlbumModel album;
170-
final bool example;
171165

172166
@override
173167
Widget build(BuildContext context) {
@@ -201,33 +195,25 @@ class AlbumCardContent extends StatelessWidget {
201195
),
202196
);
203197
}
204-
if (example) {
205-
return Image.asset(
206-
album.urlRepresentative!,
207-
fit: BoxFit.cover,
208-
errorBuilder: (context, o, s) {
209-
debugPrint("$o");
210-
return Center(child: Icon(Icons.image_not_supported));
211-
},
212-
);
213-
}
214198
return CachedNetworkImage(
215199
imageUrl: album.urlRepresentative!,
216-
imageBuilder: (context, provider) => Image(
217-
image: provider,
218-
fit: BoxFit.cover,
219-
),
220-
progressIndicatorBuilder: (context, url, download) => Center(
221-
child: CircularProgressIndicator(
222-
value: download.progress,
223-
),
224-
),
200+
fit: BoxFit.cover,
201+
progressIndicatorBuilder: (context, url, download) {
202+
if (download.downloaded >= (download.totalSize ?? 0)) {
203+
return const SizedBox();
204+
}
205+
return Center(
206+
child: CircularProgressIndicator(
207+
value: download.progress,
208+
),
209+
);
210+
},
225211
errorWidget: (context, url, error) {
226212
debugPrint("[$url] $error");
227213
return FittedBox(
228214
fit: BoxFit.cover,
229215
child: Container(
230-
padding: const EdgeInsets.all(16),
216+
padding: const EdgeInsets.all(16.0),
231217
decoration: BoxDecoration(
232218
color: Theme.of(context).scaffoldBackgroundColor,
233219
),

lib/components/cards/image_card.dart

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:auto_size_text/auto_size_text.dart';
2+
import 'package:cached_network_image/cached_network_image.dart';
23
import 'package:flutter/material.dart';
34
import 'package:piwigo_ng/models/image_model.dart';
45
import '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
},
Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import 'dart:math';
2-
31
import 'package:flutter/material.dart';
42
import 'package:piwigo_ng/components/cards/album_card.dart';
53
import 'package:piwigo_ng/models/album_model.dart';
6-
import 'package:piwigo_ng/utils/localizations.dart';
74
import 'package:piwigo_ng/utils/settings.dart';
85

96
class AlbumGridView extends StatelessWidget {
@@ -53,69 +50,3 @@ class AlbumGridView extends StatelessWidget {
5350
);
5451
}
5552
}
56-
57-
class ExampleAlbumGridView extends StatelessWidget {
58-
const ExampleAlbumGridView({
59-
Key? key,
60-
this.albumThumbnailSize = Settings.defaultAlbumThumbnailSize,
61-
}) : super(key: key);
62-
63-
final String albumThumbnailSize;
64-
65-
List<AlbumModel> get _exampleAlbumList {
66-
return [
67-
AlbumModel(
68-
id: 0,
69-
name: 'weird_cat',
70-
comment: appStrings.createNewAlbumDescription_noDescription,
71-
urlRepresentative: 'assets/example/weird_cat/$albumThumbnailSize.jpg',
72-
),
73-
AlbumModel(
74-
id: 0,
75-
name: 'weird_cat',
76-
comment: appStrings.createNewAlbumDescription_noDescription,
77-
urlRepresentative: 'assets/example/weird_cat/$albumThumbnailSize.jpg',
78-
),
79-
AlbumModel(
80-
id: 0,
81-
name: 'weird_cat',
82-
comment: appStrings.createNewAlbumDescription_noDescription,
83-
urlRepresentative: 'assets/example/weird_cat/$albumThumbnailSize.jpg',
84-
),
85-
AlbumModel(
86-
id: 0,
87-
name: 'weird_cat',
88-
comment: appStrings.createNewAlbumDescription_noDescription,
89-
urlRepresentative: 'assets/example/weird_cat/$albumThumbnailSize.jpg',
90-
),
91-
];
92-
}
93-
94-
@override
95-
Widget build(BuildContext context) {
96-
return LayoutBuilder(builder: (context, constraints) {
97-
final double nbPerRow = constraints.maxWidth / Settings.defaultAlbumGridSize;
98-
final int nbAlbums = max(nbPerRow.ceil(), 1);
99-
return GridView.builder(
100-
padding: const EdgeInsets.symmetric(vertical: 8.0),
101-
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
102-
maxCrossAxisExtent: Settings.defaultAlbumGridSize,
103-
mainAxisSpacing: 8.0,
104-
crossAxisSpacing: 8.0,
105-
childAspectRatio: AlbumCard.kAlbumRatio,
106-
),
107-
shrinkWrap: true,
108-
physics: const NeverScrollableScrollPhysics(),
109-
itemCount: nbAlbums,
110-
itemBuilder: (context, index) {
111-
AlbumModel album = _exampleAlbumList[index];
112-
return AlbumCard(
113-
album: album,
114-
example: true,
115-
showActions: false,
116-
);
117-
},
118-
);
119-
});
120-
}
121-
}

lib/components/scroll_widgets/image_grid_view.dart

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,3 @@ class _ImageGridViewState extends State<ImageGridView> {
7070
);
7171
}
7272
}
73-
74-
class ExampleImageGridView extends StatelessWidget {
75-
const ExampleImageGridView({
76-
Key? key,
77-
this.nbImageRow,
78-
this.imageThumbnailSize,
79-
}) : super(key: key);
80-
81-
final int? nbImageRow;
82-
final String? imageThumbnailSize;
83-
84-
@override
85-
Widget build(BuildContext context) {
86-
return Builder(builder: (context) {
87-
final int crossAxisCount = Settings.getImageCrossAxisCount(context, nbImageRow);
88-
return GridView.builder(
89-
padding: const EdgeInsets.symmetric(vertical: 8.0),
90-
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
91-
crossAxisCount: crossAxisCount,
92-
mainAxisSpacing: 4.0,
93-
crossAxisSpacing: 4.0,
94-
),
95-
shrinkWrap: true,
96-
physics: const NeverScrollableScrollPhysics(),
97-
itemCount: crossAxisCount,
98-
itemBuilder: (context, index) {
99-
return const SizedBox();
100-
// return ImageCard(
101-
// image: image,
102-
// example: true,
103-
// derivative: imageThumbnailSize,
104-
// );
105-
},
106-
);
107-
});
108-
}
109-
}

lib/views/image/image_view_page.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ class _ImageViewPageState extends State<ImageViewPage> {
360360

361361
// Default behavior: Zoomable image
362362
return PhotoViewGalleryPageOptions(
363+
heroAttributes: PhotoViewHeroAttributes(
364+
tag: "<hero image ${image.id}>",
365+
),
363366
imageProvider: NetworkImage(
364367
image.getDerivativeFromString(Preferences.getImageFullScreenSize)?.url ?? '',
365368
),

0 commit comments

Comments
 (0)