Skip to content

Commit 0a2e2db

Browse files
committed
refactor(ui)!: Add support for non-attachment types in attachment picker
1 parent 8c8dbd2 commit 0a2e2db

10 files changed

+1264
-747
lines changed

packages/stream_chat_flutter/lib/src/message_input/attachment_picker/options/stream_gallery_picker.dart

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:path_provider/path_provider.dart';
66
import 'package:photo_manager/photo_manager.dart';
77
import 'package:stream_chat_flutter/src/icons/stream_svg_icon.dart';
88
import 'package:stream_chat_flutter/src/message_input/attachment_picker/stream_attachment_picker.dart';
9+
import 'package:stream_chat_flutter/src/message_input/attachment_picker/stream_attachment_picker_controller.dart';
910
import 'package:stream_chat_flutter/src/misc/empty_widget.dart';
1011
import 'package:stream_chat_flutter/src/scroll_view/photo_gallery/stream_photo_gallery.dart';
1112
import 'package:stream_chat_flutter/src/scroll_view/photo_gallery/stream_photo_gallery_controller.dart';
@@ -14,7 +15,7 @@ import 'package:stream_chat_flutter/src/utils/utils.dart';
1415
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
1516

1617
/// Max image resolution which can be resized by the CDN.
17-
// Taken from https://getstream.io/chat/docs/flutter-dart/file_uploads/?language=dart#image-resizing
18+
/// Taken from https://getstream.io/chat/docs/flutter-dart/file_uploads/?language=dart#image-resizing
1819
const maxCDNImageResolution = 16800000;
1920

2021
/// Widget used to pick media from the device gallery.
@@ -23,42 +24,23 @@ class StreamGalleryPicker extends StatefulWidget {
2324
const StreamGalleryPicker({
2425
super.key,
2526
this.limit = 50,
27+
GalleryPickerConfig? config,
2628
required this.selectedMediaItems,
2729
required this.onMediaItemSelected,
28-
this.mediaThumbnailSize = const ThumbnailSize(400, 400),
29-
this.mediaThumbnailFormat = ThumbnailFormat.jpeg,
30-
this.mediaThumbnailQuality = 100,
31-
this.mediaThumbnailScale = 1,
32-
});
30+
}) : config = config ?? const GalleryPickerConfig();
3331

3432
/// Maximum number of media items that can be selected.
3533
final int limit;
3634

35+
/// Configuration for the gallery picker.
36+
final GalleryPickerConfig config;
37+
3738
/// List of selected media items.
3839
final Iterable<String> selectedMediaItems;
3940

4041
/// Callback called when an media item is selected.
4142
final ValueSetter<AssetEntity> onMediaItemSelected;
4243

43-
/// Size of the attachment thumbnails.
44-
///
45-
/// Defaults to (400, 400).
46-
final ThumbnailSize mediaThumbnailSize;
47-
48-
/// Format of the attachment thumbnails.
49-
///
50-
/// Defaults to [ThumbnailFormat.jpeg].
51-
final ThumbnailFormat mediaThumbnailFormat;
52-
53-
/// The quality value for the attachment thumbnails.
54-
///
55-
/// Valid from 1 to 100.
56-
/// Defaults to 100.
57-
final int mediaThumbnailQuality;
58-
59-
/// The scale to apply on the [attachmentThumbnailSize].
60-
final double mediaThumbnailScale;
61-
6244
@override
6345
State<StreamGalleryPicker> createState() => _StreamGalleryPickerState();
6446
}
@@ -159,10 +141,10 @@ class _StreamGalleryPickerState extends State<StreamGalleryPicker> {
159141
onMediaTap: widget.onMediaItemSelected,
160142
loadMoreTriggerIndex: 10,
161143
padding: const EdgeInsets.all(2),
162-
thumbnailSize: widget.mediaThumbnailSize,
163-
thumbnailFormat: widget.mediaThumbnailFormat,
164-
thumbnailQuality: widget.mediaThumbnailQuality,
165-
thumbnailScale: widget.mediaThumbnailScale,
144+
thumbnailSize: widget.config.mediaThumbnailSize,
145+
thumbnailFormat: widget.config.mediaThumbnailFormat,
146+
thumbnailQuality: widget.config.mediaThumbnailQuality,
147+
thumbnailScale: widget.config.mediaThumbnailScale,
166148
itemBuilder: (context, mediaItems, index, defaultWidget) {
167149
final media = mediaItems[index];
168150
return defaultWidget.copyWith(
@@ -178,6 +160,29 @@ class _StreamGalleryPickerState extends State<StreamGalleryPicker> {
178160
}
179161
}
180162

163+
/// Configuration for the [StreamGalleryPicker].
164+
class GalleryPickerConfig {
165+
/// Creates a [GalleryPickerConfig] instance.
166+
const GalleryPickerConfig({
167+
this.mediaThumbnailSize = const ThumbnailSize(400, 400),
168+
this.mediaThumbnailFormat = ThumbnailFormat.jpeg,
169+
this.mediaThumbnailQuality = 100,
170+
this.mediaThumbnailScale = 1,
171+
});
172+
173+
/// Size of the attachment thumbnails.
174+
final ThumbnailSize mediaThumbnailSize;
175+
176+
/// Format of the attachment thumbnails.
177+
final ThumbnailFormat mediaThumbnailFormat;
178+
179+
/// The quality value for the attachment thumbnails.
180+
final int mediaThumbnailQuality;
181+
182+
/// The scale to apply on the [mediaThumbnailSize].
183+
final double mediaThumbnailScale;
184+
}
185+
181186
///
182187
extension StreamImagePickerX on StreamAttachmentPickerController {
183188
///

0 commit comments

Comments
 (0)