Skip to content

Commit af04990

Browse files
Don't download the item if we already have it
1 parent a97dd30 commit af04990

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/src/sample_data.dart

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,25 @@ Future<void> downloadSampleData(List<String> portalItemIds) async {
3030
// create a portal item to ensure it exists and load to access properties
3131
final portalItem =
3232
PortalItem.withUri(Uri.parse('$portal/home/item.html?id=$itemId'));
33-
if (portalItem != null) {
34-
await portalItem.load();
35-
final itemName = portalItem.name;
36-
final filePath = '$appDirPath/$itemName';
33+
if (portalItem == null) continue;
3734

38-
final file = await File(filePath).create(recursive: true);
39-
final request = await _fetchData(portal, itemId);
40-
file.writeAsBytesSync(request.bodyBytes, flush: true);
41-
if (itemName.contains('.zip')) {
42-
// if the data is a zip we need to extract it
43-
// save all files to the device app directory in a directory with the item name without the zip extension
44-
final nameWithoutExt = itemName.replaceFirst(RegExp(r'.zip$'), '');
45-
if (!Directory.fromUri(Uri.parse('$appDirPath/$nameWithoutExt'))
46-
.existsSync()) {
47-
final dir =
48-
Directory.fromUri(Uri.parse('$appDirPath/$nameWithoutExt'));
49-
await ZipFile.extractToDirectory(zipFile: file, destinationDir: dir);
50-
// clean up the zip folder now that the data has been extracted
51-
await file.delete();
52-
}
53-
}
35+
await portalItem.load();
36+
final itemName = portalItem.name;
37+
final filePath = '$appDirPath/$itemName';
38+
final file = File(filePath);
39+
if (file.existsSync()) continue;
40+
41+
final request = await _fetchData(portal, itemId);
42+
file.createSync(recursive: true);
43+
file.writeAsBytesSync(request.bodyBytes, flush: true);
44+
45+
if (itemName.contains('.zip')) {
46+
// if the data is a zip we need to extract it
47+
// save all files to the device app directory in a directory with the item name without the zip extension
48+
final nameWithoutExt = itemName.replaceFirst(RegExp(r'.zip$'), '');
49+
final dir = Directory.fromUri(Uri.parse('$appDirPath/$nameWithoutExt'));
50+
if (dir.existsSync()) dir.deleteSync(recursive: true);
51+
await ZipFile.extractToDirectory(zipFile: file, destinationDir: dir);
5452
}
5553
}
5654
}

0 commit comments

Comments
 (0)