@@ -87,37 +87,35 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
87
87
return ;
88
88
}
89
89
90
+ final i18n = AppLocalizations .of (dialogContext);
91
+
90
92
// If possible, determine the error title and message based on the error type.
91
- bool isNetworkError = false ;
92
- String errorTitle = 'An error occurred' ;
93
- String errorMessage = error.toString ();
93
+ // (Note that issue titles and error messages are not localized)
94
+ bool allowReportIssue = true ;
95
+ String issueTitle = 'An error occurred' ;
96
+ String issueErrorMessage = error.toString ();
97
+ String errorTitle = i18n.anErrorOccurred;
98
+ String errorDescription = i18n.errorInfoDescription;
99
+ var icon = Icons .error;
94
100
95
101
if (error is TimeoutException ) {
96
- errorTitle = 'Network Timeout' ;
97
- errorMessage =
98
- 'The connection to the server timed out. Please check your internet connection and try again.' ;
102
+ issueTitle = 'Network Timeout' ;
103
+ issueErrorMessage = 'The connection to the server timed out. Please check your '
104
+ 'internet connection and try again.' ;
99
105
} else if (error is FlutterErrorDetails ) {
100
- errorTitle = 'Application Error' ;
101
- errorMessage = error.exceptionAsString ();
106
+ issueTitle = 'Application Error' ;
107
+ issueErrorMessage = error.exceptionAsString ();
102
108
} else if (error is MissingRequiredKeysException ) {
103
- errorTitle = 'Missing Required Key' ;
109
+ issueTitle = 'Missing Required Key' ;
104
110
} else if (error is SocketException ) {
105
- isNetworkError = true ;
111
+ allowReportIssue = false ;
112
+ icon = Icons .signal_wifi_connected_no_internet_4_outlined;
113
+ errorTitle = i18n.errorCouldNotConnectToServer;
114
+ errorDescription = i18n.errorCouldNotConnectToServerDetails;
106
115
}
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
- */
116
116
117
117
final String fullStackTrace = stackTrace? .toString () ?? 'No stack trace available.' ;
118
118
119
- final i18n = AppLocalizations .of (dialogContext);
120
-
121
119
showDialog (
122
120
context: dialogContext,
123
121
barrierDismissible: false ,
@@ -128,12 +126,12 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
128
126
mainAxisAlignment: MainAxisAlignment .center,
129
127
children: [
130
128
Icon (
131
- isNetworkError ? Icons .signal_wifi_connected_no_internet_4_outlined : Icons .error ,
129
+ icon ,
132
130
color: Theme .of (context).colorScheme.error,
133
131
),
134
132
Expanded (
135
133
child: Text (
136
- isNetworkError ? i18n.errorCouldNotConnectToServer : i18n.anErrorOccurred ,
134
+ errorTitle ,
137
135
style: TextStyle (color: Theme .of (context).colorScheme.error),
138
136
),
139
137
),
@@ -142,11 +140,7 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
142
140
content: SingleChildScrollView (
143
141
child: ListBody (
144
142
children: [
145
- Text (
146
- isNetworkError
147
- ? i18n.errorCouldNotConnectToServerDetails
148
- : i18n.errorInfoDescription,
149
- ),
143
+ Text (errorDescription),
150
144
const SizedBox (height: 8 ),
151
145
Text (i18n.errorInfoDescription2),
152
146
const SizedBox (height: 10 ),
@@ -155,7 +149,7 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
155
149
title: Text (i18n.errorViewDetails),
156
150
children: [
157
151
Text (
158
- errorMessage ,
152
+ issueErrorMessage ,
159
153
style: const TextStyle (fontWeight: FontWeight .bold),
160
154
),
161
155
Container (
@@ -178,14 +172,17 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
178
172
tapTargetSize: MaterialTapTargetSize .shrinkWrap,
179
173
),
180
174
onPressed: () {
181
- final String clipboardText =
182
- 'Error Title: $errorTitle \n Error Message: $errorMessage \n\n Stack Trace:\n $fullStackTrace ' ;
175
+ final String clipboardText = 'Error Title: $issueTitle \n '
176
+ 'Error Message: $issueErrorMessage \n\n '
177
+ 'Stack Trace:\n $fullStackTrace ' ;
183
178
Clipboard .setData (ClipboardData (text: clipboardText)).then ((_) {
184
179
ScaffoldMessenger .of (context).showSnackBar (
185
180
const SnackBar (content: Text ('Error details copied to clipboard!' )),
186
181
);
187
182
}).catchError ((copyError) {
188
- if (kDebugMode) logger.fine ('Error copying to clipboard: $copyError ' );
183
+ if (kDebugMode) {
184
+ logger.fine ('Error copying to clipboard: $copyError ' );
185
+ }
189
186
ScaffoldMessenger .of (context).showSnackBar (
190
187
const SnackBar (content: Text ('Could not copy details.' )),
191
188
);
@@ -198,28 +195,30 @@ void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext
198
195
),
199
196
),
200
197
actions: [
201
- if (! isNetworkError )
198
+ if (allowReportIssue )
202
199
TextButton (
203
200
child: const Text ('Report issue' ),
204
201
onPressed: () async {
205
202
final description = Uri .encodeComponent (
206
203
'## Description\n\n '
207
204
'[Please describe what you were doing when the error occurred.]\n\n '
208
205
'## Error details\n\n '
209
- 'Error title: $errorTitle \n '
210
- 'Error message: $errorMessage \n '
206
+ 'Error title: $issueTitle \n '
207
+ 'Error message: $issueErrorMessage \n '
211
208
'Stack trace:\n '
212
209
'```\n $stackTrace \n ```' ,
213
210
);
214
211
final githubIssueUrl = '$GITHUB_ISSUES_BUG_URL '
215
- '&title=$errorTitle '
212
+ '&title=$issueTitle '
216
213
'&description=$description ' ;
217
214
final Uri reportUri = Uri .parse (githubIssueUrl);
218
215
219
216
try {
220
217
await launchUrl (reportUri, mode: LaunchMode .externalApplication);
221
218
} catch (e) {
222
- if (kDebugMode) logger.warning ('Error launching URL: $e ' );
219
+ if (kDebugMode) {
220
+ logger.warning ('Error launching URL: $e ' );
221
+ }
223
222
ScaffoldMessenger .of (context).showSnackBar (
224
223
SnackBar (content: Text ('Error opening issue tracker: $e ' )),
225
224
);
0 commit comments