Skip to content

Commit c02d53f

Browse files
authored
More gracefully handle license loading failures (#87841)
1 parent ec02f3b commit c02d53f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/flutter/lib/src/material/about.dart

+11
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,17 @@ class _PackagesViewState extends State<_PackagesView> {
571571
builder: (BuildContext context, BoxConstraints constraints) {
572572
switch (snapshot.connectionState) {
573573
case ConnectionState.done:
574+
if (snapshot.hasError) {
575+
assert(() {
576+
FlutterError.reportError(FlutterErrorDetails(
577+
exception: snapshot.error!,
578+
stack: snapshot.stackTrace,
579+
context: ErrorDescription('while decoding the license file'),
580+
));
581+
return true;
582+
}());
583+
return Center(child: Text(snapshot.error.toString()));
584+
}
574585
_initDefaultDetailPage(snapshot.data!, context);
575586
return ValueListenableBuilder<int?>(
576587
valueListenable: widget.selectedId,

packages/flutter/test/material/about_test.dart

+18
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,24 @@ void main() {
997997
final double appIconBottomPadding = tester.getTopLeft(appPowered).dy - tester.getBottomLeft(appIcon).dy;
998998
expect(appIconBottomPadding, 18.0);
999999
});
1000+
1001+
testWidgets('Error handling test', (WidgetTester tester) async {
1002+
LicenseRegistry.addLicense(() => Stream<LicenseEntry>.error(Exception('Injected failure')));
1003+
await tester.pumpWidget(const MaterialApp(home: Material(child: AboutListTile())));
1004+
await tester.tap(find.byType(ListTile));
1005+
await tester.pump();
1006+
await tester.pump(const Duration(seconds: 2));
1007+
await tester.tap(find.text('VIEW LICENSES'));
1008+
await tester.pump();
1009+
await tester.pump(const Duration(seconds: 2));
1010+
final Finder finder = find.byWidgetPredicate((Widget widget) => widget.runtimeType.toString() == '_PackagesView');
1011+
// force the stream to complete (has to be done in a runAsync block since it's areal async process)
1012+
await tester.runAsync(() => (tester.firstState(finder) as dynamic).licenses as Future<dynamic>); // ignore: avoid_dynamic_calls
1013+
expect(tester.takeException().toString(), 'Exception: Injected failure');
1014+
await tester.pumpAndSettle();
1015+
expect(tester.takeException().toString(), 'Exception: Injected failure');
1016+
expect(find.text('Exception: Injected failure'), findsOneWidget);
1017+
});
10001018
}
10011019

10021020
class FakeLicenseEntry extends LicenseEntry {

0 commit comments

Comments
 (0)