Skip to content

Commit b21c542

Browse files
authored
Support overriding ErrorWidget.builder (flutter#6302)
*List which issues are fixed by this PR. You must list at least one issue.* Issue: flutter/flutter#144960
1 parent 1601b4b commit b21c542

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

packages/rfw/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ build/
7676
!**/ios/**/default.mode2v3
7777
!**/ios/**/default.pbxuser
7878
!**/ios/**/default.perspectivev3
79+
80+
# Coverage
81+
coverage/

packages/rfw/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.0.26
2+
* Supports overriding the error widget builder.
3+
14
## 1.0.25
25
* Adds support for wildget builders.
36

packages/rfw/lib/src/flutter/runtime.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,12 @@ class _Subscription {
15591559
}
15601560
}
15611561

1562-
ErrorWidget _buildErrorWidget(String message) {
1563-
FlutterError.reportError(FlutterErrorDetails(
1562+
Widget _buildErrorWidget(String message) {
1563+
final FlutterErrorDetails detail = FlutterErrorDetails(
15641564
exception: message,
15651565
stack: StackTrace.current,
15661566
library: 'Remote Flutter Widgets',
1567-
));
1568-
return ErrorWidget(message);
1567+
);
1568+
FlutterError.reportError(detail);
1569+
return ErrorWidget.builder(detail);
15691570
}

packages/rfw/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: rfw
22
description: "Remote Flutter widgets: a library for rendering declarative widget description files at runtime."
33
repository: https://github.com/flutter/packages/tree/main/packages/rfw
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+rfw%22
5-
version: 1.0.25
5+
version: 1.0.26
66

77
environment:
88
sdk: ^3.2.0

packages/rfw/test/runtime_test.dart

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void main() {
244244
),
245245
);
246246
expect(tester.takeException().toString(), contains('Could not find remote widget named'));
247-
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, 'Could not find remote widget named widget in a, possibly because some dependencies were missing: b');
247+
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, contains('Could not find remote widget named widget in a, possibly because some dependencies were missing: b'));
248248
});
249249

250250
testWidgets('Missing libraries in specified widget', (WidgetTester tester) async {
@@ -258,7 +258,7 @@ void main() {
258258
),
259259
);
260260
expect(tester.takeException().toString(), contains('Could not find remote widget named'));
261-
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, 'Could not find remote widget named widget in a, possibly because some dependencies were missing: a');
261+
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, contains('Could not find remote widget named widget in a, possibly because some dependencies were missing: a'));
262262
});
263263

264264
testWidgets('Missing libraries in import via dependency', (WidgetTester tester) async {
@@ -276,7 +276,7 @@ void main() {
276276
),
277277
);
278278
expect(tester.takeException().toString(), contains('Could not find remote widget named'));
279-
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, 'Could not find remote widget named test in a, possibly because some dependencies were missing: b');
279+
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, contains('Could not find remote widget named test in a, possibly because some dependencies were missing: b'));
280280
});
281281

282282
testWidgets('Missing widget', (WidgetTester tester) async {
@@ -291,7 +291,7 @@ void main() {
291291
),
292292
);
293293
expect(tester.takeException().toString(), contains('Could not find remote widget named'));
294-
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, 'Could not find remote widget named widget in a.');
294+
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, contains('Could not find remote widget named widget in a.'));
295295
});
296296

297297
testWidgets('Runtime', (WidgetTester tester) async {
@@ -1152,7 +1152,29 @@ void main() {
11521152

11531153
expect(tester.takeException().toString(), contains(expectedErrorMessage));
11541154
expect(find.byType(ErrorWidget), findsOneWidget);
1155-
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, expectedErrorMessage);
1155+
expect(tester.widget<ErrorWidget>(find.byType(ErrorWidget)).message, contains(expectedErrorMessage));
1156+
});
1157+
1158+
1159+
testWidgets('Customized error widget', (WidgetTester tester) async {
1160+
final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
1161+
ErrorWidget.builder = (FlutterErrorDetails details) {
1162+
return const Text('oopsie!', textDirection: TextDirection.ltr);
1163+
};
1164+
final Runtime runtime = Runtime()
1165+
..update(const LibraryName(<String>['a']), parseLibraryFile(''));
1166+
final DynamicContent data = DynamicContent();
1167+
await tester.pumpWidget(
1168+
RemoteWidget(
1169+
runtime: runtime,
1170+
data: data,
1171+
widget: const FullyQualifiedWidgetName(LibraryName(<String>['a']), 'widget'),
1172+
),
1173+
);
1174+
expect(tester.takeException().toString(), contains('Could not find remote widget named'));
1175+
expect(find.text('oopsie!'), findsOneWidget);
1176+
expect(find.byType(ErrorWidget), findsNothing);
1177+
ErrorWidget.builder = oldBuilder;
11561178
});
11571179

11581180
testWidgets('Widget builders - work when scope is not used', (WidgetTester tester) async {

0 commit comments

Comments
 (0)