-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#678): add top-level error handling
- Loading branch information
Showing
11 changed files
with
198 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,14 @@ Uri keycloakUrl([String slug = '']) => | |
// Note that sending emails will not work on the iPhone Simulator since it does | ||
// not have any email application installed. | ||
String _mailContact = '[email protected]'; | ||
Future<void> sendEmail({String subject = ''}) async { | ||
Future<void> sendEmail({String subject = '', String body = ''}) async { | ||
await launchUrl(Uri( | ||
scheme: 'mailto', | ||
path: _mailContact, | ||
queryParameters: {'subject': subject})); | ||
queryParameters: { | ||
'subject': subject, | ||
'body': Uri.encodeComponent(body), | ||
})); | ||
} | ||
|
||
final cpicMaxCacheTime = Duration(days: 90); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import '../module.dart'; | ||
|
||
class ErrorHandler extends StatefulWidget { | ||
const ErrorHandler({ | ||
super.key, | ||
required this.appRouter, | ||
required this.child, | ||
}); | ||
|
||
final AppRouter appRouter; | ||
final Widget child; | ||
|
||
@override | ||
State<StatefulWidget> createState() => ErrorHandlerState(); | ||
} | ||
|
||
class ErrorHandlerState extends State<ErrorHandler> { | ||
Future<void> _handleError({ | ||
required Object exception, | ||
StackTrace? stackTrace, | ||
}) async { | ||
debugPrint(exception.toString()); | ||
debugPrintStack(stackTrace: stackTrace); | ||
await widget.appRouter.push(ErrorRoute(error: exception.toString())); | ||
} | ||
|
||
@override | ||
void initState() { | ||
FlutterError.onError = (details) { | ||
_handleError(exception: details.exception, stackTrace: details.stack); | ||
}; | ||
WidgetsBinding.instance.platformDispatcher.onError = | ||
(exception, stackTrace) { | ||
_handleError(exception: exception, stackTrace: stackTrace); | ||
return true; | ||
}; | ||
super.initState(); | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return widget.child; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import '../common/module.dart'; | ||
|
||
// For generated routes | ||
export 'pages/error.dart'; | ||
|
||
CustomRoute errorRoute() => CustomRoute( | ||
path: '/error', | ||
page: ErrorRoute.page, | ||
transitionsBuilder: TransitionsBuilders.fadeIn, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../../common/module.dart'; | ||
|
||
@RoutePage() | ||
class ErrorPage extends StatelessWidget { | ||
const ErrorPage({required this.error, super.key}); | ||
|
||
final String error; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PopScope( | ||
canPop: false, | ||
child: PharMeLogoPage( | ||
greyscale: true, | ||
child: Column( | ||
children: [ | ||
Text( | ||
context.l10n.error_title, | ||
style: PharMeTheme.textTheme.headlineMedium, | ||
), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
RichText( | ||
textAlign: TextAlign.center, | ||
text: TextSpan( | ||
style: PharMeTheme.textTheme.bodyLarge, | ||
children: [ | ||
TextSpan( | ||
text: context.l10n.error_uncaught_message_first_part, | ||
), | ||
TextSpan( | ||
text: context.l10n.error_uncaught_message_bold_part, | ||
style: TextStyle(fontWeight: FontWeight.bold), | ||
) | ||
], | ||
), | ||
), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
RichText( | ||
textAlign: TextAlign.center, | ||
text: TextSpan( | ||
style: PharMeTheme.textTheme.bodyLarge, | ||
children: [ | ||
TextSpan(text: context.l10n.error_uncaught_message_contact), | ||
TextSpan( | ||
text: context.l10n.error_contact_link_text, | ||
style: TextStyle( | ||
color: PharMeTheme.secondaryColor, | ||
decoration: TextDecoration.underline, | ||
), | ||
recognizer: TapGestureRecognizer()..onTap = | ||
() { | ||
sendEmail( | ||
subject: context.l10n.error_mail_subject, | ||
body: context.l10n.error_mail_body(error), | ||
); | ||
}, | ||
), | ||
TextSpan( | ||
text: context.l10n.error_uncaught_message_after_link, | ||
), | ||
], | ||
), | ||
), | ||
SizedBox(height: PharMeTheme.mediumSpace), | ||
FullWidthButton(context.l10n.error_close_app, () async { | ||
if (Platform.isIOS) { | ||
exit(0); | ||
} | ||
await SystemChannels.platform.invokeMethod('SystemNavigator.pop'); | ||
}), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters