Skip to content

Commit 3de6a57

Browse files
committed
compose: Prototype image/video-from-library upload UI
Fixes: zulip#56
1 parent 06275f0 commit 3de6a57

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@
5353
<array>
5454
<string>fetch</string>
5555
</array>
56+
<key>NSPhotoLibraryUsageDescription</key>
57+
<string>Choose photos from your library and send them in Zulip messages.</string>
5658
</dict>
5759
</plist>

lib/widgets/compose_box.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,44 @@ class _AttachFileButton extends StatelessWidget {
318318
}
319319
}
320320

321+
class _AttachMediaButton extends StatelessWidget {
322+
const _AttachMediaButton({required this.contentController, required this.contentFocusNode});
323+
324+
final ContentTextEditingController contentController;
325+
final FocusNode contentFocusNode;
326+
327+
_handlePress(BuildContext context) async {
328+
FilePickerResult? result;
329+
try {
330+
result = await FilePicker.platform.pickFiles(type: FileType.media, allowMultiple: true, withReadStream: true);
331+
} catch (e) {
332+
// TODO(i18n)
333+
showErrorDialog(context: context, title: 'Error', message: e.toString());
334+
return;
335+
}
336+
if (result == null) {
337+
return; // User cancelled; do nothing
338+
}
339+
340+
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
341+
else {
342+
return;
343+
}
344+
345+
final Iterable<_File> files = result.files.map((f) {
346+
assert(f.readStream != null); // We passed `withReadStream: true` to pickFiles.
347+
return _File(content: f.readStream!, length: f.size, filename: f.name);
348+
});
349+
_uploadFiles(context: context, contentController: contentController, contentFocusNode: contentFocusNode,
350+
files: files);
351+
}
352+
353+
@override
354+
Widget build(BuildContext context) {
355+
return IconButton(icon: const Icon(Icons.image), onPressed: () => _handlePress(context));
356+
}
357+
}
358+
321359
/// The send button for StreamComposeBox.
322360
class _StreamSendButton extends StatefulWidget {
323361
const _StreamSendButton({required this.topicController, required this.contentController});
@@ -516,6 +554,7 @@ class _StreamComposeBoxState extends State<StreamComposeBox> {
516554
child: Row(
517555
children: [
518556
_AttachFileButton(contentController: _contentController, contentFocusNode: _contentFocusNode),
557+
_AttachMediaButton(contentController: _contentController, contentFocusNode: _contentFocusNode),
519558
])),
520559
]))));
521560
}

0 commit comments

Comments
 (0)