diff --git a/lib/src/compress_video_service.dart b/lib/src/compress_video_service.dart index f8d63e0c..abd4a045 100644 --- a/lib/src/compress_video_service.dart +++ b/lib/src/compress_video_service.dart @@ -1,19 +1,18 @@ import 'dart:async'; +import 'package:synchronized/synchronized.dart'; import 'package:video_compress/video_compress.dart'; class CompressVideoService { static final CompressVideoService instance = CompressVideoService._(); - + final _lock = Lock(); CompressVideoService._(); Future compressVideo(String path) async { - MediaInfo mediaInfo; - while (VideoCompress.isCompressing) { - await Future.delayed(Duration(seconds: 1)); - } - mediaInfo = await VideoCompress.compressVideo( - path, - ); - return mediaInfo; + print('VideoCompress.isCompressing: ${VideoCompress.isCompressing}'); + return _lock.synchronized(() { + return VideoCompress.compressVideo( + path, + ); + }); } } diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index d3482806..3487fb26 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -877,6 +877,11 @@ class MessageInputState extends State { ), ), ); + + setState(() { + _attachments.remove(attachment); + }); + return; } file = PlatformFile( name: file.name, diff --git a/pubspec.yaml b/pubspec.yaml index 88d8f216..412550ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: permission_handler: ^5.0.1+1 transparent_image: ^1.0.0 ezanimation: ^0.4.1 + synchronized: ^2.2.0+2 flutter: assets: