Let sliver.dart _createErrorWidget work with other Widgets (#30880)

Credit to @ymback
This commit is contained in:
Dan Field 2019-04-11 00:31:06 -07:00 committed by GitHub
parent 2736c8c19f
commit 42d3464d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -1291,8 +1291,8 @@ class KeepAlive extends ParentDataWidget<SliverWithKeepAliveWidget> {
} }
} }
// Return an ErrorWidget for the given Exception // Return a Widget for the given Exception
ErrorWidget _createErrorWidget(dynamic exception, StackTrace stackTrace) { Widget _createErrorWidget(dynamic exception, StackTrace stackTrace) {
final FlutterErrorDetails details = FlutterErrorDetails( final FlutterErrorDetails details = FlutterErrorDetails(
exception: exception, exception: exception,
stack: stackTrace, stack: stackTrace,

View File

@ -195,4 +195,19 @@ void main() {
expect(find.text('B'), findsNothing); expect(find.text('B'), findsNothing);
expect(find.text('BOTTOM'), findsOneWidget); expect(find.text('BOTTOM'), findsOneWidget);
}); });
testWidgets('Can override ErrorWidget.build', (WidgetTester tester) async {
const Text errorText = Text('error');
final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
ErrorWidget.builder = (FlutterErrorDetails details) => errorText;
final SliverChildBuilderDelegate builderThrowsDelegate = SliverChildBuilderDelegate(
(_, __) => throw 'builder',
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
addSemanticIndexes: false,
);
expect(builderThrowsDelegate.build(null, 0), errorText);
expect(tester.takeException(), 'builder');
ErrorWidget.builder = oldBuilder;
});
} }