Skip to content

Commit

Permalink
Use the right onError Flutter method for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Dec 19, 2024
1 parent 66216a7 commit aeac25f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions test/test_provider_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,27 @@ Future<Widget> 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,
Expand Down Expand Up @@ -210,21 +229,3 @@ Future<Widget> 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;
}
}

0 comments on commit aeac25f

Please sign in to comment.