From 91f49d18f4a4af8c1843e7396fe480bbe78355ee Mon Sep 17 00:00:00 2001 From: Vishnu Kumar Date: Sun, 17 May 2026 10:49:32 +0530 Subject: [PATCH] android: File picker shows all files instead of image gallery UI Fixes #1490 where the file picker shows all file types instead of filtering to images only. Changes: - Configured file picker with proper MIME type filter to show image gallery UI - Modified the test for file upload and Added a new test for image upload scenarios Video reference documenting the fix is available in the PR. Fixes: #1490 --- lib/widgets/compose_box.dart | 2 +- test/widgets/compose_box_test.dart | 53 ++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/widgets/compose_box.dart b/lib/widgets/compose_box.dart index 90e64ffa8..875130cb8 100644 --- a/lib/widgets/compose_box.dart +++ b/lib/widgets/compose_box.dart @@ -1172,7 +1172,7 @@ class _AttachMediaButton extends _AttachUploadsButton { @override Future> getFiles(BuildContext context) async { // TODO(#114): This doesn't give quite the right UI on Android. - return _getFilePickerFiles(context, FileType.media); + return _getFilePickerFiles(context, FileType.image); } } diff --git a/test/widgets/compose_box_test.dart b/test/widgets/compose_box_test.dart index 7599fb5cb..016f2161e 100644 --- a/test/widgets/compose_box_test.dart +++ b/test/widgets/compose_box_test.dart @@ -1140,6 +1140,55 @@ void main() { await tester.pump(); } + group('attach file', () { + testWidgets('success', (tester) async { + await prepare(tester); + checkAppearsLoading(tester, false); + + testBinding.pickFilesResult = FilePickerResult([PlatformFile( + readStream: Stream.fromIterable(['asdf'.codeUnits]), + path:'/private/var/mobile/Containers/Data/Application/foo/tmp/file.pdf', + name: 'file.pdf', + size: 12345, + ),]); + connection.prepare(delay: const Duration(seconds: 1),json: + UploadFileResult(url: '/user_uploads/1/4e/m2A3MSqFnWRLUf9SaPzQ0Up_/file.pdf',).toJson(), + ); + await tester.tap(find.byIcon(ZulipIcons.attach_file)); + await tester.pump(); + final call = testBinding.takePickFilesCalls().single; + check(call.allowMultiple).equals(true); + check(call.type).equals(FileType.any); + checkNoDialog(tester); + check(controller!.content.text,) + .equals('see image: [Uploading file.pdf…]()\n\n'); + check(connection.lastRequest!).isA() + ..method.equals('POST') + ..files.single.which( + (it) => it + ..field.equals('file') + ..length.equals(12345) + ..filename.equals('file.pdf') + ..contentType.asString.equals( + 'application/pdf', + ) // ← different MIME type + ..has>>( + (f) => f.finalize().toBytes(), + 'contents', + ).completes( + (it) => it.deepEquals(['asdf'.codeUnits].expand((l) => l)), + ), + ); + checkAppearsLoading(tester, true); + + await tester.pump(const Duration(seconds: 1)); + check(controller!.content.text).equals( + 'see image: [file.pdf](/user_uploads/1/4e/m2A3MSqFnWRLUf9SaPzQ0Up_/file.pdf)\n\n', + ); + checkAppearsLoading(tester, false); + }); + }); + group('attach from media library', () { testWidgets('success', (tester) async { await prepare(tester); @@ -1160,7 +1209,7 @@ void main() { await tester.pump(); final call = testBinding.takePickFilesCalls().single; check(call.allowMultiple).equals(true); - check(call.type).equals(FileType.media); + check(call.type).equals(FileType.image); checkNoDialog(tester); @@ -2544,4 +2593,4 @@ enum _EditInteractionStart { _EditInteractionStart.restoreFailedEdit => 'from restoring a failed edit', }; } -} +} \ No newline at end of file