Skip to content

Commit

Permalink
chore: Follow up gallery picker
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Feb 25, 2025
1 parent cc41a3b commit eb446af
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 22 deletions.
30 changes: 10 additions & 20 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,12 @@ class ChatController extends State<ChatPageWithRoom>
});
}

void sendFileAction() async {
final files = await selectFiles(context, allowMultiple: true);
void sendFileAction({FileSelectorType type = FileSelectorType.any}) async {
final files = await selectFiles(
context,
allowMultiple: true,
type: type,
);
if (files.isEmpty) return;
await showAdaptiveDialog(
context: context,
Expand All @@ -547,23 +551,6 @@ class ChatController extends State<ChatPageWithRoom>
);
}

void sendImageAction() async {
final files = await ImagePicker().pickMultipleMedia(
imageQuality: null,
requestFullMetadata: false,
);
if (files.isEmpty) return;

await showAdaptiveDialog(
context: context,
builder: (c) => SendFileDialog(
files: files,
room: room,
outerContext: context,
),
);
}

void openCameraAction() async {
// Make sure the textfield is unfocused before opening the camera
FocusScope.of(context).requestFocus(FocusNode());
Expand Down Expand Up @@ -1139,7 +1126,10 @@ class ChatController extends State<ChatPageWithRoom>
sendFileAction();
}
if (choice == 'image') {
sendImageAction();
sendFileAction(type: FileSelectorType.images);
}
if (choice == 'video') {
sendFileAction(type: FileSelectorType.videos);
}
if (choice == 'camera') {
openCameraAction();
Expand Down
16 changes: 14 additions & 2 deletions lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,21 @@ class ChatInputRow extends StatelessWidget {
leading: CircleAvatar(
backgroundColor: theme.colorScheme.onPrimaryContainer,
foregroundColor: theme.colorScheme.primaryContainer,
child: const Icon(Icons.photo_album_outlined),
child: const Icon(Icons.photo_outlined),
),
title: Text(L10n.of(context).openGallery),
title: Text(L10n.of(context).sendImage),
contentPadding: const EdgeInsets.all(0),
),
),
PopupMenuItem<String>(
value: 'video',
child: ListTile(
leading: CircleAvatar(
backgroundColor: theme.colorScheme.onPrimaryContainer,
foregroundColor: theme.colorScheme.primaryContainer,
child: const Icon(Icons.video_camera_back_outlined),
),
title: Text(L10n.of(context).sendVideo),
contentPadding: const EdgeInsets.all(0),
),
),
Expand Down
62 changes: 62 additions & 0 deletions lib/utils/file_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,72 @@ enum FileSelectorType {
label: 'WEBP',
extensions: <String>['WebP', 'WEBP'],
),
XTypeGroup(
label: 'GIF',
extensions: <String>['gif', 'GIF'],
),
XTypeGroup(
label: 'BMP',
extensions: <String>['bmp', 'BMP'],
),
XTypeGroup(
label: 'TIFF',
extensions: <String>['tiff', 'TIFF', 'tif', 'TIF'],
),
XTypeGroup(
label: 'HEIC',
extensions: <String>['heic', 'HEIC'],
),
XTypeGroup(
label: 'SVG',
extensions: <String>['svg', 'SVG'],
),
],
FileType.image,
null,
),
videos(
[
XTypeGroup(
label: 'MP4',
extensions: <String>['mp4', 'MP4'],
),
XTypeGroup(
label: 'AVI',
extensions: <String>['avi', 'AVI'],
),
XTypeGroup(
label: 'MOV',
extensions: <String>['mov', 'MOV'],
),
XTypeGroup(
label: 'MKV',
extensions: <String>['mkv', 'MKV'],
),
XTypeGroup(
label: 'WMV',
extensions: <String>['wmv', 'WMV'],
),
XTypeGroup(
label: 'FLV',
extensions: <String>['flv', 'FLV'],
),
XTypeGroup(
label: 'MPEG',
extensions: <String>['mpeg', 'MPEG'],
),
XTypeGroup(
label: '3GP',
extensions: <String>['3gp', '3GP'],
),
XTypeGroup(
label: 'OGG',
extensions: <String>['ogg', 'OGG'],
),
],
FileType.video,
null,
),
zip(
[
XTypeGroup(
Expand Down

0 comments on commit eb446af

Please sign in to comment.