diff --git a/app/lib/common/constants.dart b/app/lib/common/constants.dart index f954726b..93aa165f 100644 --- a/app/lib/common/constants.dart +++ b/app/lib/common/constants.dart @@ -24,7 +24,8 @@ const cpicLookupUrl = const drugInteractionIndicator = '*'; const drugInteractionIndicatorName = 'asterisk'; -const testErrorMessage = 'THIS IS A TEST'; +const nonFatalTestErrorMessage = 'THIS IS A NON-FATAL TEST'; +const fatalTestErrorMessage = 'THIS IS A FATAL TEST'; // For shorter uniqueness check that also does not rely on variant; also format // HLA-A (which is currently unique) as HLA-B diff --git a/app/lib/common/widgets/error_handler.dart b/app/lib/common/widgets/error_handler.dart index aba27be9..b6cfcb58 100644 --- a/app/lib/common/widgets/error_handler.dart +++ b/app/lib/common/widgets/error_handler.dart @@ -1,3 +1,5 @@ +import 'package:flutter/foundation.dart'; + import '../module.dart'; class ErrorHandler extends StatefulWidget { @@ -39,14 +41,15 @@ class ErrorHandlerState extends State { } } + bool _isNonFatalTestError(Object exception) { + return exception.toString().contains(nonFatalTestErrorMessage); + } + bool _needToHandleError(Object exception) { - // Set to false to test that error screen appears (annoying when debugging - // with breakpoints anyways) - const ignoreTestError = true; - final isTestError = exception.toString().contains(testErrorMessage); + final ignoreTestError = kDebugMode && _isNonFatalTestError(exception); final isOverflowError = exception is FlutterError && exception.message.startsWith('A RenderFlex overflowed'); - final willIgnoreError = isOverflowError || (isTestError && ignoreTestError); + final willIgnoreError = isOverflowError || ignoreTestError; return !willIgnoreError; } diff --git a/app/lib/more/pages/more.dart b/app/lib/more/pages/more.dart index 5b30fde8..de6f55b1 100644 --- a/app/lib/more/pages/more.dart +++ b/app/lib/more/pages/more.dart @@ -80,12 +80,22 @@ class MorePage extends StatelessWidget { if (kDebugMode) _buildSettingsItem( title: 'Throw Flutter Error', style: TextStyle(color: PharMeTheme.errorColor), - onTap: () => throw FlutterError(testErrorMessage), + onTap: () => throw FlutterError(nonFatalTestErrorMessage), ), if (kDebugMode) _buildSettingsItem( title: 'Throw Other Error', style: TextStyle(color: PharMeTheme.errorColor), - onTap: () async => throw Exception(testErrorMessage), + onTap: () async => throw Exception(nonFatalTestErrorMessage), + ), + if (kDebugMode) _buildSettingsItem( + title: 'Throw Flutter Error (Fatal)', + style: TextStyle(color: PharMeTheme.errorColor), + onTap: () => throw FlutterError(fatalTestErrorMessage), + ), + if (kDebugMode) _buildSettingsItem( + title: 'Throw Other Error (Fatal)', + style: TextStyle(color: PharMeTheme.errorColor), + onTap: () async => throw Exception(fatalTestErrorMessage), ), ] ),