@@ -49,7 +49,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, {BuildContext? co
49
49
return ;
50
50
}
51
51
52
- final errorList = formatErrors (extractErrors (exception.errors));
52
+ final errorList = formatApiErrors (extractErrors (exception.errors));
53
53
54
54
showDialog (
55
55
context: dialogContext,
@@ -104,6 +104,15 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
104
104
} else if (error is SocketException ) {
105
105
isNetworkError = true ;
106
106
}
107
+ /*
108
+ else if (error is PlatformException) {
109
+ errorTitle = 'Problem with media';
110
+ errorMessage =
111
+ 'There was a problem loading the media. This can be a e.g. problem with the codec that'
112
+ 'is not supported by your device. Original error message: ${error.message}';
113
+ }
114
+
115
+ */
107
116
108
117
final String fullStackTrace = stackTrace? .toString () ?? 'No stack trace available.' ;
109
118
@@ -115,13 +124,13 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
115
124
builder: (BuildContext context) {
116
125
return AlertDialog (
117
126
title: Row (
127
+ spacing: 8 ,
118
128
mainAxisAlignment: MainAxisAlignment .center,
119
129
children: [
120
130
Icon (
121
131
isNetworkError ? Icons .signal_wifi_connected_no_internet_4_outlined : Icons .error,
122
132
color: Theme .of (context).colorScheme.error,
123
133
),
124
- const SizedBox (width: 8 ),
125
134
Expanded (
126
135
child: Text (
127
136
isNetworkError ? i18n.errorCouldNotConnectToServer : i18n.anErrorOccurred,
@@ -309,7 +318,7 @@ List<ApiError> extractErrors(Map<String, dynamic> errors) {
309
318
}
310
319
311
320
/// Processes the error messages from the server and returns a list of widgets
312
- List <Widget > formatErrors (List <ApiError > errors, {Color ? color}) {
321
+ List <Widget > formatApiErrors (List <ApiError > errors, {Color ? color}) {
313
322
final textColor = color ?? Colors .black;
314
323
315
324
final List <Widget > errorList = [];
@@ -328,6 +337,26 @@ List<Widget> formatErrors(List<ApiError> errors, {Color? color}) {
328
337
return errorList;
329
338
}
330
339
340
+ /// Processes the error messages from the server and returns a list of widgets
341
+ List <Widget > formatTextErrors (List <String > errors, {String ? title, Color ? color}) {
342
+ final textColor = color ?? Colors .black;
343
+
344
+ final List <Widget > errorList = [];
345
+
346
+ if (title != null ) {
347
+ errorList.add (
348
+ Text (title, style: TextStyle (fontWeight: FontWeight .bold, color: textColor)),
349
+ );
350
+ }
351
+
352
+ for (final message in errors) {
353
+ errorList.add (Text (message, style: TextStyle (color: textColor)));
354
+ }
355
+ errorList.add (const SizedBox (height: 8 ));
356
+
357
+ return errorList;
358
+ }
359
+
331
360
class FormHttpErrorsWidget extends StatelessWidget {
332
361
final WgerHttpException exception;
333
362
@@ -338,11 +367,32 @@ class FormHttpErrorsWidget extends StatelessWidget {
338
367
return Column (
339
368
children: [
340
369
Icon (Icons .error_outline, color: Theme .of (context).colorScheme.error),
341
- ...formatErrors (
370
+ ...formatApiErrors (
342
371
extractErrors (exception.errors),
343
372
color: Theme .of (context).colorScheme.error,
344
373
),
345
374
],
346
375
);
347
376
}
348
377
}
378
+
379
+ class GeneralErrorsWidget extends StatelessWidget {
380
+ final String ? title;
381
+ final List <String > widgets;
382
+
383
+ const GeneralErrorsWidget (this .widgets, {this .title, super .key});
384
+
385
+ @override
386
+ Widget build (BuildContext context) {
387
+ return Column (
388
+ children: [
389
+ Icon (Icons .error_outline, color: Theme .of (context).colorScheme.error),
390
+ ...formatTextErrors (
391
+ widgets,
392
+ title: title,
393
+ color: Theme .of (context).colorScheme.error,
394
+ ),
395
+ ],
396
+ );
397
+ }
398
+ }
0 commit comments