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.
This commit is contained in:
@@ -14,8 +14,9 @@ Future<String> 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<int> bytes =
|
||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
||||
await File(target).writeAsBytes(bytes);
|
||||
|
||||
@@ -45,8 +45,8 @@ Future<String> 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<int> bytes =
|
||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
||||
await (await File(target).create(recursive: true)).writeAsBytes(bytes);
|
||||
|
||||
Reference in New Issue
Block a user