diff --git a/test/test_provider_scope.dart b/test/test_provider_scope.dart index 05b4b91743..c025467349 100644 --- a/test/test_provider_scope.dart +++ b/test/test_provider_scope.dart @@ -142,8 +142,27 @@ Future makeTestProviderScope( if (userSession != null) kSessionStorageKey: jsonEncode(userSession.toJson()), }); + final flutterTestOnError = FlutterError.onError!; + + void ignoreOverflowErrors(FlutterErrorDetails details) { + bool isOverflowError = false; + final exception = details.exception; + + if (exception is FlutterError) { + isOverflowError = exception.diagnostics.any( + (e) => e.value.toString().contains('A RenderFlex overflowed by'), + ); + } + + if (isOverflowError) { + // debugPrint('Overflow error detected.'); + } else { + flutterTestOnError(details); + } + } + // TODO consider loading true fonts as well - FlutterError.onError = _ignoreOverflowErrors; + FlutterError.onError = ignoreOverflowErrors; return ProviderScope( key: key, @@ -210,21 +229,3 @@ Future makeTestProviderScope( child: TestSurface(size: surfaceSize, child: child), ); } - -void _ignoreOverflowErrors(FlutterErrorDetails details, {bool forceReport = false}) { - bool isOverflowError = false; - final exception = details.exception; - - if (exception is FlutterError) { - isOverflowError = exception.diagnostics.any( - (e) => e.value.toString().contains('A RenderFlex overflowed by'), - ); - } - - if (isOverflowError) { - // debugPrint('Overflow error detected.'); - } else { - FlutterError.dumpErrorToConsole(details, forceReport: forceReport); - throw exception; - } -}