Grain flutter app
1import 'package:flutter/material.dart';
2import 'package:grain/models/gallery.dart';
3import 'package:grain/widgets/app_image.dart';
4
5class GalleryPreview extends StatelessWidget {
6 final Gallery gallery;
7
8 const GalleryPreview({super.key, required this.gallery});
9
10 @override
11 Widget build(BuildContext context) {
12 final theme = Theme.of(context);
13 final Color bgColor = theme.brightness == Brightness.dark
14 ? Colors.grey[850]!
15 : Colors.grey[200]!;
16 final photos = gallery.items
17 .where((item) => item.thumb != null && item.thumb!.isNotEmpty)
18 .toList();
19 return AspectRatio(
20 aspectRatio: 3 / 2,
21 child: Row(
22 children: [
23 Expanded(
24 flex: 2,
25 child: photos.isNotEmpty
26 ? AppImage(
27 url: photos[0].thumb,
28 fit: BoxFit.cover,
29 width: double.infinity,
30 height: double.infinity,
31 )
32 : Container(color: theme.colorScheme.surfaceContainerHighest),
33 ),
34 const SizedBox(width: 2),
35 Expanded(
36 flex: 1,
37 child: Column(
38 children: [
39 Expanded(
40 child: photos.length > 1
41 ? AppImage(
42 url: photos[1].thumb,
43 fit: BoxFit.cover,
44 width: double.infinity,
45 height: double.infinity,
46 )
47 : Container(color: bgColor),
48 ),
49 const SizedBox(height: 2),
50 Expanded(
51 child: photos.length > 2
52 ? AppImage(
53 url: photos[2].thumb,
54 fit: BoxFit.cover,
55 width: double.infinity,
56 height: double.infinity,
57 )
58 : Container(color: bgColor),
59 ),
60 ],
61 ),
62 ),
63 ],
64 ),
65 );
66 }
67}