Skip to content

Commit

Permalink
TW-688 Mobile avoid Freeze when uploading file
Browse files Browse the repository at this point in the history
  • Loading branch information
drminh2807 committed Sep 27, 2023
1 parent 27e6a9f commit 58a0938
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ abstract class AppConfig {
static const String defaultImageBlurHash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
static const String defaultVideoBlurHash = 'L5H2EC=PM+yV0g-mq.wG9c010J}I';
static const int thumbnailQuality = 70;
static const int blurHashSize = 32;

static String? issueId;

Expand Down
26 changes: 22 additions & 4 deletions lib/presentation/extensions/send_file_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fluffychat/presentation/model/file/file_asset_entity.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:image/image.dart' as img;
import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:flutter/foundation.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
Expand Down Expand Up @@ -364,10 +365,27 @@ extension SendFileExtension on Room {
}

Future<String?> _generateBlurHash(String filePath) async {
final image = await img.decodeImageFile(filePath);
if (image == null) return null;
final blurHash = BlurHash.encode(image, numCompX: 4, numCompY: 3);
return blurHash.hash;
try {
final stopwatch = Stopwatch()..start();
final result = await FlutterImageCompress.compressWithFile(
filePath,
minHeight: AppConfig.blurHashSize,
minWidth: AppConfig.blurHashSize,
);
Logs().d('_generateBlurHash::compress ${stopwatch.elapsed}');
final blurHash = await compute(
(imageData) {
final image = img.decodeJpg(imageData);
return BlurHash.encode(image!, numCompX: 4, numCompY: 3);
},
result!,
);
Logs().d('_generateBlurHash::encode ${stopwatch.elapsed}');
return blurHash.hash;
} catch (e) {
Logs().e('_generateBlurHash::error', e);
return null;
}
}

Future<ImageFileInfo> _getThumbnailVideo(
Expand Down

0 comments on commit 58a0938

Please sign in to comment.