From 75800ccdd5263707f73d8a2bc37f93b2a8b7ce31 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 25 Aug 2024 08:59:35 +0200 Subject: [PATCH] chore: Follow up send file dialog fix --- lib/pages/chat/send_file_dialog.dart | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index 79b4eed83..edcb981f3 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -33,6 +31,8 @@ class SendFileDialogState extends State { static const int minSizeToCompress = 20 * 1024; Future _send() async { + final scaffoldMessenger = ScaffoldMessenger.of(context); + final l10n = L10n.of(context)!; for (var file in widget.files) { MatrixImageFile? thumbnail; if (file is MatrixVideoFile && file.bytes.length > minSizeToCompress) { @@ -44,20 +44,24 @@ class SendFileDialogState extends State { }, ); } - try { - await widget.room.sendFileEvent( - file, - thumbnail: thumbnail, - shrinkImageMaxDimension: origImage ? null : 1600, - ); - } on IOException catch (_) { - } on FileTooBigMatrixException catch (_) { - } catch (e, s) { - if (mounted) { + widget.room + .sendFileEvent( + file, + thumbnail: thumbnail, + shrinkImageMaxDimension: origImage ? null : 1600, + ) + .catchError( + (e, s) { + if (e is FileTooBigMatrixException) { + scaffoldMessenger.showSnackBar( + SnackBar(content: Text(l10n.fileIsTooBigForServer)), + ); + return null; + } ErrorReporter(context, 'Unable to send file').onErrorCallback(e, s); - } - rethrow; - } + return null; + }, + ); } Navigator.of(context, rootNavigator: false).pop();