forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotos_grid.dart
More file actions
93 lines (88 loc) · 3.26 KB
/
Copy pathphotos_grid.dart
File metadata and controls
93 lines (88 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import 'package:flutter/material.dart';
import 'package:omi/backend/schema/conversation.dart';
import 'package:omi/widgets/conversation_photo_image.dart';
import 'package:omi/widgets/media_viewer_page.dart';
class PhotosGridComponent extends StatelessWidget {
final List<ConversationPhoto> photos;
final String? conversationId;
const PhotosGridComponent({super.key, required this.photos, this.conversationId});
@override
Widget build(BuildContext context) {
return GridView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: photos.length,
itemBuilder: (context, idx) {
final photo = photos[idx];
final isProcessing = !photo.discarded && photo.description == null;
return GestureDetector(
key: ValueKey(photo.id),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MediaViewerPage(items: _mediaItemsFor(photos, conversationId), initialIndex: idx),
),
);
},
child: Hero(
tag: photo.id,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Stack(
fit: StackFit.expand,
children: [
ConversationPhotoImage(
photo: photo,
conversationId: conversationId,
fit: BoxFit.cover,
color: photo.discarded ? const Color(0xFF35343B) : null,
colorBlendMode: photo.discarded ? BlendMode.saturation : null,
),
if (photo.discarded)
Container(
color: Colors.black.withValues(alpha: 0.5),
child: const Icon(Icons.visibility_off_outlined, color: Colors.white70, size: 28),
),
if (isProcessing)
Container(
color: Colors.black.withValues(alpha: 0.5),
child: const Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2.0,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
),
],
),
),
),
);
},
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 800 / 600,
),
);
}
}
List<MediaViewerItem> _mediaItemsFor(List<ConversationPhoto> photos, String? conversationId) {
return photos.map((photo) {
final hasInlineBytes = photo.base64.isNotEmpty;
return MediaViewerItem(
base64: hasInlineBytes ? photo.base64 : null,
bytesLoader: hasInlineBytes ? null : () => loadConversationPhotoBytes(photo, conversationId),
mimeType: photo.contentType,
heroTag: photo.id,
showCaptionStrip: true,
caption: photo.description,
discarded: photo.discarded,
);
}).toList();
}