From c1b5fce01b351230df1e66795f88c3f75d0515a5 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 30 Jul 2024 18:24:56 +0800 Subject: [PATCH] Fix copying asset files for flutter examples. (#1191) If the target file exists but has a different file size, we need to copy the source file to the target file. --- flutter-examples/streaming_asr/lib/utils.dart | 5 +++-- flutter-examples/tts/lib/utils.dart | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/flutter-examples/streaming_asr/lib/utils.dart b/flutter-examples/streaming_asr/lib/utils.dart index 5f311a26..e93618c7 100644 --- a/flutter-examples/streaming_asr/lib/utils.dart +++ b/flutter-examples/streaming_asr/lib/utils.dart @@ -14,8 +14,9 @@ Future copyAssetFile(String src, [String? dst]) async { final target = join(directory.path, dst); bool exists = await new File(target).exists(); - if (!exists) { - final data = await rootBundle.load(src); + final data = await rootBundle.load(src); + + if (!exists || File(target).lengthSync() != data.lengthInBytes) { final List bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); await File(target).writeAsBytes(bytes); diff --git a/flutter-examples/tts/lib/utils.dart b/flutter-examples/tts/lib/utils.dart index eba5c97c..206eb12c 100644 --- a/flutter-examples/tts/lib/utils.dart +++ b/flutter-examples/tts/lib/utils.dart @@ -45,8 +45,8 @@ Future copyAssetFile(String src, [String? dst]) async { final target = p.join(directory.path, dst); bool exists = await new File(target).exists(); - if (!exists) { - final data = await rootBundle.load(src); + final data = await rootBundle.load(src); + if (!exists || File(target).lengthSync() != data.lengthInBytes) { final List bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); await (await File(target).create(recursive: true)).writeAsBytes(bytes);