From b28ae1259757da75e9d8e16a35557b59c3705c81 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 3 Mar 2021 12:47:19 +0100 Subject: [PATCH] fix: minor --- .gitignore | 2 +- packages/stream_chat/lib/src/api/channel.dart | 1 + .../lib/src/attachment_file_uploader.dart | 48 ++++++-- .../stream_chat_flutter/example/pubspec.yaml | 6 +- .../lib/src/message_input.dart | 10 +- .../stream_chat_flutter/lib/src/utils.dart | 112 +++++++++--------- .../stream_chat_flutter_core/pubspec.yaml | 6 +- packages/stream_chat_persistence/pubspec.yaml | 6 +- 8 files changed, 114 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index f7a23bbb..c75573b2 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,7 @@ build/ .project .classpath .settings -/.fvm +**/.fvm .melos_tool/ /packages/flutter_widgets/example/ios/Flutter/.last_build_id diff --git a/packages/stream_chat/lib/src/api/channel.dart b/packages/stream_chat/lib/src/api/channel.dart index 667f28a1..ea32bc38 100644 --- a/packages/stream_chat/lib/src/api/channel.dart +++ b/packages/stream_chat/lib/src/api/channel.dart @@ -277,6 +277,7 @@ class Channel { ); } }).catchError((e, stk) { + client.logger.severe('error uploading the attachment', e, stk); updateAttachment( it.copyWith(uploadState: UploadState.failed(error: e.toString())), ); diff --git a/packages/stream_chat/lib/src/attachment_file_uploader.dart b/packages/stream_chat/lib/src/attachment_file_uploader.dart index 33d9b351..7d9e8c40 100644 --- a/packages/stream_chat/lib/src/attachment_file_uploader.dart +++ b/packages/stream_chat/lib/src/attachment_file_uploader.dart @@ -70,16 +70,28 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { ProgressCallback onSendProgress, CancelToken cancelToken, }) async { - final filename = file.path?.split('/')?.last; + final filename = file.path?.split('/')?.last ?? file.name; final mimeType = filename.mimeType; + + MultipartFile multiPartFile; + if (file.path != null) { + multiPartFile = await MultipartFile.fromFile( + file.path, + filename: filename, + contentType: mimeType, + ); + } else if (file.bytes != null) { + multiPartFile = MultipartFile.fromBytes( + file.bytes, + filename: filename, + contentType: mimeType, + ); + } + final response = await _client.post( '/channels/$channelType/$channelId/image', data: FormData.fromMap({ - 'file': await MultipartFile.fromFile( - file.path, - filename: filename, - contentType: mimeType, - ), + 'file': multiPartFile, }), onSendProgress: onSendProgress, cancelToken: cancelToken, @@ -95,16 +107,28 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader { ProgressCallback onSendProgress, CancelToken cancelToken, }) async { - final filename = file.path?.split('/')?.last; + final filename = file.path?.split('/')?.last ?? file.name; final mimeType = filename.mimeType; + + MultipartFile multiPartFile; + if (file.path != null) { + multiPartFile = await MultipartFile.fromFile( + file.path, + filename: filename, + contentType: mimeType, + ); + } else if (file.bytes != null) { + multiPartFile = MultipartFile.fromBytes( + file.bytes, + filename: filename, + contentType: mimeType, + ); + } + final response = await _client.post( '/channels/$channelType/$channelId/file', data: FormData.fromMap({ - 'file': await MultipartFile.fromFile( - file.path, - filename: filename, - contentType: mimeType, - ), + 'file': multiPartFile, }), onSendProgress: onSendProgress, cancelToken: cancelToken, diff --git a/packages/stream_chat_flutter/example/pubspec.yaml b/packages/stream_chat_flutter/example/pubspec.yaml index 4d32fb58..0c7ac24d 100644 --- a/packages/stream_chat_flutter/example/pubspec.yaml +++ b/packages/stream_chat_flutter/example/pubspec.yaml @@ -25,7 +25,11 @@ dependencies: sdk: flutter stream_chat_flutter: path: ../ - stream_chat_persistence: ^1.3.0-beta + stream_chat_persistence: + git: + url: https://github.com/GetStream/stream-chat-flutter.git + ref: develop + path: packages/stream_chat_persistence # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index 21424c2e..9cb152ad 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -304,7 +304,7 @@ class MessageInputState extends State { Flex _buildTextField(BuildContext context) { return Flex( direction: Axis.horizontal, - crossAxisAlignment: CrossAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.center, children: [ if (!_commandEnabled) _buildExpandActionsButton(), if (widget.actionsLocation == ActionsLocation.left) @@ -1903,14 +1903,12 @@ class MessageInputState extends State { if (file == null) return; - final mimeType = file.path.split('/').last.mimeType; + final mimeType = file.name?.mimeType; final extraDataMap = {}; - if (camera) { - if (mimeType.type == 'video' || mimeType.type == 'image') { - attachmentType = mimeType.type; - } + if (mimeType.type == 'video' || mimeType.type == 'image') { + attachmentType = mimeType.type; } else { attachmentType = 'file'; } diff --git a/packages/stream_chat_flutter/lib/src/utils.dart b/packages/stream_chat_flutter/lib/src/utils.dart index 7a88ee6c..150f4f33 100644 --- a/packages/stream_chat_flutter/lib/src/utils.dart +++ b/packages/stream_chat_flutter/lib/src/utils.dart @@ -36,63 +36,65 @@ Future showConfirmationDialog( )), builder: (context) { final effect = StreamChatTheme.of(context).colorTheme.borderTop; - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox(height: 26.0), - if (icon != null) icon, - SizedBox(height: 26.0), - Text( - title, - style: StreamChatTheme.of(context).textTheme.headlineBold, - ), - SizedBox(height: 7.0), - Text( - question, - textAlign: TextAlign.center, - ), - SizedBox(height: 36.0), - Container( - color: effect.color.withOpacity(effect.alpha ?? 1), - height: 1, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextButton( - child: Text( - cancelText, - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .black - .withOpacity(0.5)), + return SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox(height: 26.0), + if (icon != null) icon, + SizedBox(height: 26.0), + Text( + title, + style: StreamChatTheme.of(context).textTheme.headlineBold, + ), + SizedBox(height: 7.0), + Text( + question, + textAlign: TextAlign.center, + ), + SizedBox(height: 36.0), + Container( + color: effect.color.withOpacity(effect.alpha ?? 1), + height: 1, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton( + child: Text( + cancelText, + style: StreamChatTheme.of(context) + .textTheme + .bodyBold + .copyWith( + color: StreamChatTheme.of(context) + .colorTheme + .black + .withOpacity(0.5)), + ), + onPressed: () { + Navigator.of(context).pop(false); + }, ), - onPressed: () { - Navigator.of(context).pop(false); - }, - ), - TextButton( - child: Text( - okText, - style: StreamChatTheme.of(context) - .textTheme - .bodyBold - .copyWith( - color: StreamChatTheme.of(context) - .colorTheme - .accentRed), + TextButton( + child: Text( + okText, + style: StreamChatTheme.of(context) + .textTheme + .bodyBold + .copyWith( + color: StreamChatTheme.of(context) + .colorTheme + .accentRed), + ), + onPressed: () { + Navigator.pop(context, true); + }, ), - onPressed: () { - Navigator.pop(context, true); - }, - ), - ], - ), - ], + ], + ), + ], + ), ); }); } diff --git a/packages/stream_chat_flutter_core/pubspec.yaml b/packages/stream_chat_flutter_core/pubspec.yaml index 7f3d6ad0..f3659b4e 100644 --- a/packages/stream_chat_flutter_core/pubspec.yaml +++ b/packages/stream_chat_flutter_core/pubspec.yaml @@ -10,7 +10,11 @@ environment: flutter: ">=1.17.0" dependencies: - stream_chat: ^1.3.2+1-beta + stream_chat: + git: + url: https://github.com/GetStream/stream-chat-flutter.git + ref: develop + path: packages/stream_chat flutter: sdk: flutter rxdart: ^0.25.0 diff --git a/packages/stream_chat_persistence/pubspec.yaml b/packages/stream_chat_persistence/pubspec.yaml index 6923e927..99a780fa 100644 --- a/packages/stream_chat_persistence/pubspec.yaml +++ b/packages/stream_chat_persistence/pubspec.yaml @@ -15,7 +15,11 @@ dependencies: path: ^1.7.0 path_provider: ^1.6.27 sqlite3_flutter_libs: ^0.4.0+1 - stream_chat: ^1.3.0-beta + stream_chat: + git: + url: https://github.com/GetStream/stream-chat-flutter.git + ref: develop + path: packages/stream_chat dev_dependencies: test: ^1.15.7