diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..e4c6f701 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Build + +on: + push: + branches: + - master + - feature/new-ui + release: + types: + - created + +jobs: + build_and_deploy_ios: + runs-on: [macos-latest] + steps: + - uses: actions/checkout@v2 + - name: Install RubyGems + run: | + cd example/ios + bundle install + - uses: subosito/flutter-action@v1.4.0 + with: + channel: 'stable' + - name: Install firebase-tools + run: npm install -g firebase-tools + - name: Flutter setup + run: | + cd example + flutter pub get + - name: Build and release + env: + MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} + MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }} + FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} + run: | + cd example + flutter build ios --release --no-codesign + cd ios + bundle exec fastlane deploy_to_firebase + build_and_deploy_android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: '12.x' + - uses: subosito/flutter-action@v1.4.0 + with: + channel: 'stable' + - run: | + cd example + flutter pub get + - name: Build + run: | + cd example + flutter build apk + - name: Deploy + uses: wzieba/Firebase-Distribution-Github-Action@v1.2.1 + with: + appId: ${{secrets.FIREBASE_ANDROID_APPID}} + token: ${{secrets.FIREBASE_TOKEN}} + groups: stream-testers + file: example/build/app/outputs/apk/release/app-release.apk diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index ca43c066..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: CI - -on: - push: - branches: - - master - - feature/new-ui - -jobs: - build_and_deploy_ios: - runs-on: [macos-latest] - steps: - - uses: actions/checkout@v2 - - name: Install RubyGems - run: | - cd example/ios - bundle install - - uses: subosito/flutter-action@v1.3.2 - with: - channel: 'stable' - - name: Install firebase-tools - run: npm install -g firebase-tools - - name: Flutter setup - run: | - cd example - flutter pub get - - name: Coverage fix - run: | - file=test/coverage_helper_test.dart - echo "// Helper file to make coverage work for all dart files\n" > $file - echo "// ignore_for_file: unused_import" >> $file - find lib -name '*.dart' | grep -e '[^g]\.dart' | grep -v '_html.dart' | cut -c4- | awk -v package=stream_chat_flutter '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file - echo "" >> $file - echo "void main(){}" >> $file - cat $file - - name: Run tests - run: flutter test --coverage - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) -c -t ${{ secrets.CODECOV_TOKEN }} -f coverage/lcov.info -F flutter_tool - - name: Build and release - env: - MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} - MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }} - FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} - run: | - cd example - flutter build ios --release --no-codesign - cd ios - bundle exec fastlane deploy_to_firebase - build_and_deploy_android: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v1 - with: - java-version: '12.x' - - uses: subosito/flutter-action@v1.3.2 - with: - channel: 'stable' - - run: | - cd example - flutter pub get - - name: Coverage fix - run: | - file=test/coverage_helper_test.dart - echo "// Helper file to make coverage work for all dart files\n" > $file - echo "// ignore_for_file: unused_import" >> $file - find lib -name '*.dart' | grep -e '[^g]\.dart' | grep -v '_html.dart' | cut -c4- | awk -v package=stream_chat_flutter '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file - echo "" >> $file - echo "void main(){}" >> $file - cat $file - - name: Run tests - run: flutter test --coverage - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) -c -t ${{ secrets.CODECOV_TOKEN }} -f coverage/lcov.info -F flutter_tool - - name: Build - run: | - cd example - flutter build apk - - name: Deploy - uses: wzieba/Firebase-Distribution-Github-Action@v1.2.1 - with: - appId: ${{secrets.FIREBASE_ANDROID_APPID}} - token: ${{secrets.FIREBASE_TOKEN}} - groups: stream-testers - file: example/build/app/outputs/apk/release/app-release.apk diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..a8e87c58 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: + pull_request: +jobs: + test: + runs-on: [ubuntu-latest] + steps: + - uses: actions/checkout@v2 + - name: Flutter action + uses: subosito/flutter-action@v1.3.2 + with: + channel: 'stable' + - name: Get dependencies + run: flutter pub get + - name: Coverage fix + run: | + file=test/coverage_helper_test.dart + echo "// Helper file to make coverage work for all dart files\n" > $file + echo "// ignore_for_file: unused_import" >> $file + find lib -name '*.dart' | grep -e '[^g]\.dart' | grep -v '_html.dart' | cut -c4- | awk -v package=stream_chat_flutter '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file + echo "" >> $file + echo "void main(){}" >> $file + cat $file + - name: Run tests + run: flutter test --coverage + - name: Codecov + run: bash <(curl -s https://codecov.io/bash) -c -t ${{ secrets.CODECOV_TOKEN }} -f coverage/lcov.info -F flutter_tool diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 474bfd75..c5ff1b9e 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,8 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 29 + ndkVersion '21.3.6528147' sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +41,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.example" minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id index 661f8167..5d3809be 100644 --- a/example/ios/Flutter/.last_build_id +++ b/example/ios/Flutter/.last_build_id @@ -1 +1 @@ -89eb023669fee58472de747080d78b5a \ No newline at end of file +bdf1751976c4ee1e2ef7638eabcfd1ea \ No newline at end of file diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 0068f96c..d20eaee6 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -33,49 +33,45 @@ PODS: - file_picker (0.0.1): - DKImagePickerController/PhotoGallery - Flutter - - Firebase/CoreOnly (6.26.0): - - FirebaseCore (= 6.7.2) - - Firebase/Messaging (6.26.0): + - Firebase/CoreOnly (6.33.0): + - FirebaseCore (= 6.10.3) + - Firebase/Messaging (6.33.0): - Firebase/CoreOnly - - FirebaseMessaging (~> 4.4.1) - - firebase_core (0.5.0-1): - - Firebase/CoreOnly (~> 6.26.0) + - FirebaseMessaging (~> 4.7.0) + - firebase_core (0.5.1): + - Firebase/CoreOnly (~> 6.33.0) - Flutter - firebase_messaging (7.0.3): - - Firebase/CoreOnly (~> 6.26.0) - - Firebase/Messaging (~> 6.26.0) + - Firebase/CoreOnly (~> 6.33.0) + - Firebase/Messaging (~> 6.33.0) - firebase_core - Flutter - - FirebaseAnalyticsInterop (1.5.0) - - FirebaseCore (6.7.2): - - FirebaseCoreDiagnostics (~> 1.3) - - FirebaseCoreDiagnosticsInterop (~> 1.2) - - GoogleUtilities/Environment (~> 6.5) - - GoogleUtilities/Logger (~> 6.5) + - FirebaseCore (6.10.3): + - FirebaseCoreDiagnostics (~> 1.6) + - GoogleUtilities/Environment (~> 6.7) + - GoogleUtilities/Logger (~> 6.7) - FirebaseCoreDiagnostics (1.7.0): - GoogleDataTransport (~> 7.4) - GoogleUtilities/Environment (~> 6.7) - GoogleUtilities/Logger (~> 6.7) - nanopb (~> 1.30906.0) - - FirebaseCoreDiagnosticsInterop (1.2.0) - - FirebaseInstallations (1.3.0): - - FirebaseCore (~> 6.6) - - GoogleUtilities/Environment (~> 6.6) - - GoogleUtilities/UserDefaults (~> 6.6) + - FirebaseInstallations (1.7.0): + - FirebaseCore (~> 6.10) + - GoogleUtilities/Environment (~> 6.7) + - GoogleUtilities/UserDefaults (~> 6.7) - PromisesObjC (~> 1.2) - - FirebaseInstanceID (4.3.4): - - FirebaseCore (~> 6.6) - - FirebaseInstallations (~> 1.0) - - GoogleUtilities/Environment (~> 6.5) - - GoogleUtilities/UserDefaults (~> 6.5) - - FirebaseMessaging (4.4.1): - - FirebaseAnalyticsInterop (~> 1.5) - - FirebaseCore (~> 6.6) - - FirebaseInstanceID (~> 4.3) - - GoogleUtilities/AppDelegateSwizzler (~> 6.5) - - GoogleUtilities/Environment (~> 6.5) - - GoogleUtilities/Reachability (~> 6.5) - - GoogleUtilities/UserDefaults (~> 6.5) + - FirebaseInstanceID (4.8.0): + - FirebaseCore (~> 6.10) + - FirebaseInstallations (~> 1.6) + - GoogleUtilities/Environment (~> 6.7) + - GoogleUtilities/UserDefaults (~> 6.7) + - FirebaseMessaging (4.7.1): + - FirebaseCore (~> 6.10) + - FirebaseInstanceID (~> 4.7) + - GoogleUtilities/AppDelegateSwizzler (~> 6.7) + - GoogleUtilities/Environment (~> 6.7) + - GoogleUtilities/Reachability (~> 6.7) + - GoogleUtilities/UserDefaults (~> 6.7) - Protobuf (>= 3.9.2, ~> 3.9) - Flutter (1.0.0) - flutter_apns (0.0.1): @@ -119,9 +115,9 @@ PODS: - Flutter - PromisesObjC (1.2.11) - Protobuf (3.13.0) - - SDWebImage (5.9.3): - - SDWebImage/Core (= 5.9.3) - - SDWebImage/Core (5.9.3) + - SDWebImage (5.9.4): + - SDWebImage/Core (= 5.9.4) + - SDWebImage/Core (5.9.4) - shared_preferences (0.0.1): - Flutter - sqflite (0.0.2): @@ -146,7 +142,7 @@ PODS: - sqlite3/perf-threadsafe - sqlite3/rtree - Starscream (4.0.4) - - StreamChatClient (2.4.0): + - StreamChatClient (2.4.1): - Starscream (~> 4.0) - SwiftyGif (5.3.0) - url_launcher (0.0.1): @@ -180,10 +176,8 @@ SPEC REPOS: - DKImagePickerController - DKPhotoGallery - Firebase - - FirebaseAnalyticsInterop - FirebaseCore - FirebaseCoreDiagnostics - - FirebaseCoreDiagnosticsInterop - FirebaseInstallations - FirebaseInstanceID - FirebaseMessaging @@ -237,16 +231,14 @@ SPEC CHECKSUMS: DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179 file_picker: 3e6c3790de664ccf9b882732d9db5eaf6b8d4eb1 - Firebase: 7cf5f9c67f03cb3b606d1d6535286e1080e57eb6 - firebase_core: 00e54a4744164a6b5a250b96dd1ad5afaba7a342 - firebase_messaging: 666d9994651b1ecf8c582b52dd913f3fa58c17ef - FirebaseAnalyticsInterop: 3f86269c38ae41f47afeb43ebf32a001f58fcdae - FirebaseCore: f42e5e5f382cdcf6b617ed737bf6c871a6947b17 + Firebase: 8db6f2d1b2c5e2984efba4949a145875a8f65fe5 + firebase_core: aa25a5dc6b492ecab37587c53d8420135f0cac90 + firebase_messaging: 0aea2cd5885b65e19ede58ee3507f485c992cc75 + FirebaseCore: d889d9e12535b7f36ac8bfbf1713a0836a3012cd FirebaseCoreDiagnostics: 770ac5958e1372ce67959ae4b4f31d8e127c3ac1 - FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850 - FirebaseInstallations: 6f5f680e65dc374397a483c32d1799ba822a395b - FirebaseInstanceID: cef67c4967c7cecb56ea65d8acbb4834825c587b - FirebaseMessaging: 29543feb343b09546ab3aa04d008ee8595b43c44 + FirebaseInstallations: 466c7b4d1f58fe16707693091da253726a731ed2 + FirebaseInstanceID: bd3ffc24367f901a43c063b36c640b345a4a5dd1 + FirebaseMessaging: 5eca4ef173de76253352511aafef774caa1cba2a Flutter: 0e3d915762c693b495b44d77113d4970485de6ec flutter_apns: ddc629f26016140bf52165040b0a8e8869f9ce32 flutter_app_badger: 65de4d6f0c34a891df49e6cfb8a1c0496426fa68 @@ -260,13 +252,13 @@ SPEC CHECKSUMS: path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c PromisesObjC: 8c196f5a328c2cba3e74624585467a557dcb482f Protobuf: 3dac39b34a08151c6d949560efe3f86134a3f748 - SDWebImage: a31ee8e90a97303529e03fb0c333eae0eacb88e9 + SDWebImage: b69257f4ab14e9b6a2ef53e910fdf914d8f757c1 shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904 sqlite3: 8f7d2078ae27778699a622a94b853285793422a2 sqlite3_flutter_libs: 5651f8ff48e3b44d910863c4ea5916085b1b245f Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9 - StreamChatClient: 8c83a141e753e45fa096ff56d4b782d59e46f251 + StreamChatClient: d061cf52babcd9df930aee9cf864ab0379427eff SwiftyGif: e466e86c660d343357ab944a819a101c4127cb40 url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e diff --git a/example/pubspec.yaml b/example/pubspec.yaml index dac40d3b..842f471c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: example description: A new Flutter project. -version: 1.0.37+39 +version: 1.0.39+41 environment: sdk: ">=2.2.2 <3.0.0" diff --git a/images/giphy_icon.png b/images/giphy_icon.png new file mode 100644 index 00000000..ea99e834 Binary files /dev/null and b/images/giphy_icon.png differ diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index d03a61bc..7bdbfd5d 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -1,9 +1,9 @@ import 'dart:async'; -import 'dart:io'; import 'dart:math'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:http_parser/http_parser.dart'; @@ -17,7 +17,7 @@ import 'package:stream_chat_flutter/src/user_avatar.dart'; import '../stream_chat_flutter.dart'; import 'stream_channel.dart'; -typedef FileUploader = Future Function(File, Channel); +typedef FileUploader = Future Function(PlatformFile, Channel); typedef AttachmentThumbnailBuilder = Widget Function( BuildContext, _SendingAttachment, @@ -223,10 +223,14 @@ class MessageInputState extends State { return Row( children: [ Checkbox( - value: _sendAsDm, - onChanged: (val) => setState(() { - _sendAsDm = val; - })), + value: _sendAsDm, + onChanged: (val) => setState( + () { + _sendAsDm = val; + }, + ), + activeColor: StreamChatTheme.of(context).accentColor, + ), Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text('Send also as direct message'), @@ -278,21 +282,21 @@ class MessageInputState extends State { Expanded _buildTextInput(BuildContext context) { return Expanded( child: Center( - child: LimitedBox( - maxHeight: widget.maxHeight, - child: Container( - clipBehavior: Clip.antiAlias, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(32.0), - border: Border.all( - color: Colors.grey, - ), + child: Container( + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(32.0), + border: Border.all( + color: Colors.grey, ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - _buildAttachments(), - TextField( + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + _buildAttachments(), + LimitedBox( + maxHeight: widget.maxHeight, + child: TextField( key: Key('messageInputText'), enabled: _inputEnabled, minLines: null, @@ -360,7 +364,10 @@ class MessageInputState extends State { autofocus: false, textAlignVertical: TextAlignVertical.center, decoration: InputDecoration( - hintText: 'Write a message', + hintText: + (_commandEnabled && _chosenCommand.name == 'giphy') + ? 'Search GIFs' + : 'Write a message', prefixText: _commandEnabled ? null : ' ', border: OutlineInputBorder( borderSide: BorderSide(color: Colors.transparent)), @@ -404,8 +411,8 @@ class MessageInputState extends State { ), textCapitalization: TextCapitalization.sentences, ), - ], - ), + ) + ], ), ), ), @@ -467,6 +474,9 @@ class MessageInputState extends State { padding: const EdgeInsets.all(8.0), child: Card( elevation: 2.0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), color: StreamChatTheme.of(context).primaryColor, clipBehavior: Clip.antiAlias, child: Container( @@ -503,6 +513,18 @@ class MessageInputState extends State { ...commands .map( (c) => ListTile( + leading: c.name == 'giphy' + ? CircleAvatar( + backgroundColor: Colors.black, + child: Image.asset( + 'images/giphy_icon.png', + package: 'stream_chat_flutter', + width: 16.0, + height: 16.0, + ), + maxRadius: 12.0, + ) + : null, title: Text.rich( TextSpan( text: '${c.name.capitalize()}', @@ -525,7 +547,7 @@ class MessageInputState extends State { color: Colors.white, size: 12.5, ), - maxRadius: 15, + maxRadius: 12, ), //subtitle: Text(c.description), onTap: () { @@ -576,6 +598,9 @@ class MessageInputState extends State { margin: EdgeInsets.all(8.0), elevation: 2.0, color: StreamChatTheme.of(context).primaryColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), clipBehavior: Clip.antiAlias, child: Container( constraints: BoxConstraints.loose(Size.fromHeight(400)), @@ -605,9 +630,9 @@ class MessageInputState extends State { '${m.user.name}', style: TextStyle(fontWeight: FontWeight.bold), ), - subtitle: Text('${m.userId}'), + subtitle: Text('@${m.userId}'), trailing: Icon( - Icons.alternate_email, + StreamIcons.at_mention, color: StreamChatTheme.of(context).accentColor, ), onTap: () { @@ -752,8 +777,8 @@ class MessageInputState extends State { case 'image': case 'giphy': return attachment.file != null - ? Image.file( - attachment.file, + ? Image.memory( + attachment.file.bytes, fit: BoxFit.cover, ) : Image.network( @@ -782,7 +807,10 @@ class MessageInputState extends State { child: Padding( padding: const EdgeInsets.only( left: 4.0, right: 8.0, top: 8.0, bottom: 8.0), - child: Icon(StreamIcons.lightning), + child: Icon( + StreamIcons.lightning, + color: Color(0xFF000000).withAlpha(128), + ), ), onTap: () { if (_commandsOverlay == null) { @@ -804,7 +832,10 @@ class MessageInputState extends State { child: Padding( padding: EdgeInsets.only(left: 8.0, right: padding, top: 8.0, bottom: 8.0), - child: Icon(StreamIcons.attach), + child: Icon( + StreamIcons.attach, + color: Color(0xFF000000).withAlpha(128), + ), ), onTap: () { showAttachmentModal(); @@ -857,22 +888,24 @@ class MessageInputState extends State { Navigator.pop(context); }, ), - ListTile( - leading: Icon(Icons.camera_alt), - title: Text('Photo from camera'), - onTap: () { - pickFile(DefaultAttachmentTypes.image, true); - Navigator.pop(context); - }, - ), - ListTile( - leading: Icon(Icons.videocam), - title: Text('Video from camera'), - onTap: () { - pickFile(DefaultAttachmentTypes.video, true); - Navigator.pop(context); - }, - ), + if (!kIsWeb) + ListTile( + leading: Icon(Icons.camera_alt), + title: Text('Photo from camera'), + onTap: () { + pickFile(DefaultAttachmentTypes.image, true); + Navigator.pop(context); + }, + ), + if (!kIsWeb) + ListTile( + leading: Icon(Icons.videocam), + title: Text('Video from camera'), + onTap: () { + pickFile(DefaultAttachmentTypes.video, true); + Navigator.pop(context); + }, + ), ListTile( leading: Icon(Icons.insert_drive_file), title: Text('Upload a file'), @@ -904,7 +937,7 @@ class MessageInputState extends State { _inputEnabled = false; }); - File file; + PlatformFile file; String attachmentType; if (fileType == DefaultAttachmentTypes.image) { @@ -922,7 +955,11 @@ class MessageInputState extends State { } else if (fileType == DefaultAttachmentTypes.video) { pickedFile = await _imagePicker.getVideo(source: ImageSource.camera); } - file = File(pickedFile.path); + final bytes = await pickedFile.readAsBytes(); + file = PlatformFile( + path: pickedFile.path, + bytes: bytes, + ); } else { FileType type; if (fileType == DefaultAttachmentTypes.image) { @@ -932,9 +969,13 @@ class MessageInputState extends State { } else if (fileType == DefaultAttachmentTypes.file) { type = FileType.any; } - final res = await FilePicker.platform.pickFiles(type: type); + final res = await FilePicker.platform.pickFiles( + type: type, + withData: true, + ); if (res?.files?.isNotEmpty == true) { - file = File(res.files.first.path); + file = res.files.single; + print('file.bytes?.length: ${file.bytes?.length}'); } } @@ -947,11 +988,10 @@ class MessageInputState extends State { } final channel = StreamChannel.of(context).channel; - final attachment = _SendingAttachment( file: file, attachment: Attachment( - localUri: file.uri, + localUri: file.path != null ? Uri.parse(file.path) : null, type: attachmentType, ), ); @@ -978,7 +1018,7 @@ class MessageInputState extends State { } Future _uploadAttachment( - File file, + PlatformFile file, DefaultAttachmentTypes type, Channel channel, ) async { @@ -999,9 +1039,9 @@ class MessageInputState extends State { return url; } - Future _uploadImage(File file, Channel channel) async { - final filename = file.path.split('/').last; - final bytes = await file.readAsBytes(); + Future _uploadImage(PlatformFile file, Channel channel) async { + final filename = file.name ?? file.path?.split('/')?.last; + final bytes = file.bytes; final res = await channel.sendImage( MultipartFile.fromBytes( bytes, @@ -1012,9 +1052,9 @@ class MessageInputState extends State { return res.file; } - Future _uploadFile(File file, Channel channel) async { - final filename = file.path.split('/').last; - final bytes = await file.readAsBytes(); + Future _uploadFile(PlatformFile file, Channel channel) async { + final filename = file.name ?? file.path?.split('/')?.last; + final bytes = file.bytes; final res = await channel.sendFile( MultipartFile.fromBytes( bytes, @@ -1037,7 +1077,7 @@ class MessageInputState extends State { sendMessage(); }, child: Icon( - StreamIcons.send_message, + _getIdleSendIcon(), color: Colors.grey, ), )), @@ -1056,21 +1096,42 @@ class MessageInputState extends State { onTap: () { sendMessage(); }, - child: Transform.rotate( - angle: widget.editMessage == null ? -pi / 2 : 0, - child: Icon( - widget.editMessage == null - ? StreamIcons.send_message - : StreamIcons.check_send, - color: StreamChatTheme.of(context).accentColor, - ), - ), + child: _getSendIcon(), ), ), ), ); } + IconData _getIdleSendIcon() { + if (_commandEnabled) { + return StreamIcons.search; + } else { + return StreamIcons.send_message; + } + } + + Widget _getSendIcon() { + if (widget.editMessage != null) { + return Icon( + StreamIcons.check_send, + color: StreamChatTheme.of(context).accentColor, + ); + } else if (_commandEnabled) { + return Icon( + StreamIcons.search, + color: StreamChatTheme.of(context).accentColor, + ); + } else { + return Transform.rotate( + angle: -pi / 2, + child: Icon( + StreamIcons.send_message, + color: StreamChatTheme.of(context).accentColor, + )); + } + } + /// Sends the current message void sendMessage() async { var text = textEditingController.text.trim(); @@ -1157,34 +1218,36 @@ class MessageInputState extends State { void initState() { super.initState(); - _keyboardListener = KeyboardVisibility.onChange.listen((visible) { - if (visible) { - if (_commandsOverlay != null) { - if (textEditingController.text.startsWith('/')) { - WidgetsBinding.instance.addPostFrameCallback((_) { - _commandsOverlay = _buildCommandsOverlayEntry(); - Overlay.of(context).insert(_commandsOverlay); - }); + if (!kIsWeb) { + _keyboardListener = KeyboardVisibility.onChange.listen((visible) { + if (visible) { + if (_commandsOverlay != null) { + if (textEditingController.text.startsWith('/')) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _commandsOverlay = _buildCommandsOverlayEntry(); + Overlay.of(context).insert(_commandsOverlay); + }); + } } - } - if (_mentionsOverlay != null) { - if (textEditingController.text.contains('@')) { - WidgetsBinding.instance.addPostFrameCallback((_) { - _mentionsOverlay = _buildCommandsOverlayEntry(); - Overlay.of(context).insert(_mentionsOverlay); - }); + if (_mentionsOverlay != null) { + if (textEditingController.text.contains('@')) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _mentionsOverlay = _buildCommandsOverlayEntry(); + Overlay.of(context).insert(_mentionsOverlay); + }); + } + } + } else { + if (_commandsOverlay != null) { + _commandsOverlay.remove(); + } + if (_mentionsOverlay != null) { + _mentionsOverlay.remove(); } } - } else { - if (_commandsOverlay != null) { - _commandsOverlay.remove(); - } - if (_mentionsOverlay != null) { - _mentionsOverlay.remove(); - } - } - }); + }); + } textEditingController = widget.textEditingController ?? TextEditingController(); @@ -1211,7 +1274,7 @@ class MessageInputState extends State { void dispose() { _commandsOverlay?.remove(); _mentionsOverlay?.remove(); - _keyboardListener.cancel(); + _keyboardListener?.cancel(); super.dispose(); } @@ -1227,7 +1290,7 @@ class MessageInputState extends State { } class _SendingAttachment { - File file; + PlatformFile file; Attachment attachment; bool uploaded; diff --git a/pubspec.yaml b/pubspec.yaml index 99db379b..d61e6874 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,6 +34,8 @@ dependencies: widgets_visibility_provider: ^2.0.2 flutter: + assets: + - images/giphy_icon.png fonts: - family: stream-icons fonts: