From ebcaed87710640c9dfef3ce6c9ec0d787740a665 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 26 Nov 2020 11:44:14 +0100 Subject: [PATCH] add singleton trick --- lib/src/compress_video_service.dart | 9 ++++++--- lib/src/message_input.dart | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/compress_video_service.dart b/lib/src/compress_video_service.dart index 56b11d1e..43d2c79c 100644 --- a/lib/src/compress_video_service.dart +++ b/lib/src/compress_video_service.dart @@ -2,10 +2,10 @@ import 'dart:async'; import 'package:synchronized/synchronized.dart'; import 'package:video_compress/video_compress.dart'; -class CompressVideoService { - static final CompressVideoService instance = CompressVideoService._(); +class ICompressVideoService { + static final ICompressVideoService instance = ICompressVideoService._(); final _lock = Lock(); - CompressVideoService._(); + ICompressVideoService._(); Future compressVideo(String path) async { return _lock.synchronized(() { @@ -15,3 +15,6 @@ class CompressVideoService { }); } } + +ICompressVideoService get CompressVideoService => + ICompressVideoService.instance; diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 3487fb26..c9ed15bb 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -866,8 +866,7 @@ class MessageInputState extends State { if (file.size > _kMaxAttachmentSize) { if (medium.mediaType == MediaType.video) { - final mediaInfo = - await CompressVideoService.instance.compressVideo(file.path); + final mediaInfo = await CompressVideoService.compressVideo(file.path); if (mediaInfo.filesize / (1024 * 1024) > _kMaxAttachmentSize) { Scaffold.of(context).showSnackBar( @@ -1561,8 +1560,7 @@ class MessageInputState extends State { if (file.size > _kMaxAttachmentSize) { if (attachmentType == 'video') { - final mediaInfo = - await CompressVideoService.instance.compressVideo(file.path); + final mediaInfo = await CompressVideoService.compressVideo(file.path); file = PlatformFile( name: mediaInfo.title, size: mediaInfo.filesize,