Skip to content

Commit bf36dec

Browse files
authored
feat: display a warning dialog when local resources must be side-loaded (#1085)
* fix: check for missing local resources after download attempts * fix: refine error handling for missing resources and distinguish warning messages in dialogs * fix: improve warning message format for missing side-loaded files * fix: standardize button colors in error dialog to use theme colors
1 parent bef3ded commit bf36dec

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

flutter/lib/resources/resource_manager.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ class ResourceManager {
144144
}
145145
// delete downloaded archives to free up disk space
146146
await cacheManager.deleteArchives(internetPaths);
147+
148+
// After attempting downloads, check for missing local resources (e.g., accuracy datasets)
149+
if (downloadMissing) {
150+
final missingLocalResources = <String>[];
151+
for (final resource in resources) {
152+
if (!resource.path.startsWith(_dataPrefix)) continue;
153+
final resolvedPath = get(resource.path);
154+
if (resolvedPath.isEmpty) {
155+
missingLocalResources.add(resource.path);
156+
continue;
157+
}
158+
final exists = await File(resolvedPath).exists() ||
159+
await Directory(resolvedPath).exists();
160+
if (!exists) {
161+
missingLocalResources.add(resource.path);
162+
}
163+
}
164+
if (missingLocalResources.isNotEmpty) {
165+
final dataFolder = getDataFolder();
166+
final missingList =
167+
missingLocalResources.map((e) => '\n - $e').join();
168+
throw 'WARN: Some required files must be side-loaded.\nPlease copy the files to the application data folder and retry.\nMissing files:$missingList\nData folder:\n$dataFolder';
169+
}
170+
}
147171
} finally {
148172
_loadingPath = '';
149173
_loadingProgress = 1.0;

flutter/lib/ui/error_dialog.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,8 @@ Future<void> _showPopupDialog(BuildContext context, DialogTypeEnum type,
8787
ElevatedButton(
8888
onPressed: () => Navigator.of(context).pop(),
8989
style: ElevatedButton.styleFrom(
90-
backgroundColor: type == DialogTypeEnum.error
91-
? Colors.red
92-
: type == DialogTypeEnum.warning
93-
? Colors.amber
94-
: Colors.green,
95-
foregroundColor: Colors.white,
96-
padding:
97-
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
90+
backgroundColor: Theme.of(context).colorScheme.primary,
91+
foregroundColor: Theme.of(context).colorScheme.onPrimary,
9892
),
9993
child: Text(l10n.dialogOk),
10094
),
@@ -107,16 +101,19 @@ Future<void> _showPopupDialog(BuildContext context, DialogTypeEnum type,
107101
);
108102
}
109103

110-
Future<void> showWarningDialog(
111-
BuildContext context, List<String> messages) async {
112-
final l10n = AppLocalizations.of(context)!;
113-
await _showPopupDialog(
114-
context, DialogTypeEnum.warning, l10n.dialogTitleWarning, messages);
115-
}
116-
117104
Future<void> showErrorDialog(
118105
BuildContext context, List<String> messages) async {
119106
final l10n = AppLocalizations.of(context)!;
107+
108+
// Use the "WARN" prefix in messages to distinguish warnings from errors,
109+
// so the dialog can be styled appropriately based on the detected type.
110+
final isWarning = messages.any((m) => m.startsWith('WARN'));
111+
if (isWarning) {
112+
await _showPopupDialog(
113+
context, DialogTypeEnum.warning, l10n.dialogTitleWarning, messages);
114+
return;
115+
}
116+
120117
await _showPopupDialog(
121118
context, DialogTypeEnum.error, l10n.dialogTitleError, messages);
122119
}
@@ -204,8 +201,8 @@ Future<void> showResourceMissingDialog(
204201
);
205202
},
206203
style: ElevatedButton.styleFrom(
207-
backgroundColor: Colors.blue,
208-
foregroundColor: Colors.white,
204+
backgroundColor: Theme.of(context).colorScheme.primary,
205+
foregroundColor: Theme.of(context).colorScheme.onPrimary,
209206
padding:
210207
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
211208
),

0 commit comments

Comments
 (0)