More gracefully handle license loading failures (#87841)
This commit is contained in:
parent
ec02f3bfb7
commit
c02d53fc0e
@ -571,6 +571,17 @@ class _PackagesViewState extends State<_PackagesView> {
|
|||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
switch (snapshot.connectionState) {
|
switch (snapshot.connectionState) {
|
||||||
case ConnectionState.done:
|
case ConnectionState.done:
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
assert(() {
|
||||||
|
FlutterError.reportError(FlutterErrorDetails(
|
||||||
|
exception: snapshot.error!,
|
||||||
|
stack: snapshot.stackTrace,
|
||||||
|
context: ErrorDescription('while decoding the license file'),
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
return Center(child: Text(snapshot.error.toString()));
|
||||||
|
}
|
||||||
_initDefaultDetailPage(snapshot.data!, context);
|
_initDefaultDetailPage(snapshot.data!, context);
|
||||||
return ValueListenableBuilder<int?>(
|
return ValueListenableBuilder<int?>(
|
||||||
valueListenable: widget.selectedId,
|
valueListenable: widget.selectedId,
|
||||||
|
@ -997,6 +997,24 @@ void main() {
|
|||||||
final double appIconBottomPadding = tester.getTopLeft(appPowered).dy - tester.getBottomLeft(appIcon).dy;
|
final double appIconBottomPadding = tester.getTopLeft(appPowered).dy - tester.getBottomLeft(appIcon).dy;
|
||||||
expect(appIconBottomPadding, 18.0);
|
expect(appIconBottomPadding, 18.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Error handling test', (WidgetTester tester) async {
|
||||||
|
LicenseRegistry.addLicense(() => Stream<LicenseEntry>.error(Exception('Injected failure')));
|
||||||
|
await tester.pumpWidget(const MaterialApp(home: Material(child: AboutListTile())));
|
||||||
|
await tester.tap(find.byType(ListTile));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(seconds: 2));
|
||||||
|
await tester.tap(find.text('VIEW LICENSES'));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(seconds: 2));
|
||||||
|
final Finder finder = find.byWidgetPredicate((Widget widget) => widget.runtimeType.toString() == '_PackagesView');
|
||||||
|
// force the stream to complete (has to be done in a runAsync block since it's areal async process)
|
||||||
|
await tester.runAsync(() => (tester.firstState(finder) as dynamic).licenses as Future<dynamic>); // ignore: avoid_dynamic_calls
|
||||||
|
expect(tester.takeException().toString(), 'Exception: Injected failure');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.takeException().toString(), 'Exception: Injected failure');
|
||||||
|
expect(find.text('Exception: Injected failure'), findsOneWidget);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeLicenseEntry extends LicenseEntry {
|
class FakeLicenseEntry extends LicenseEntry {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user