From 4ae5252f8ac4577da3018eef04fb2866de976d0b Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Wed, 15 Feb 2023 11:14:06 +0300 Subject: [PATCH] Fix license page crash (#120728) --- packages/flutter/lib/src/material/about.dart | 6 +- .../flutter/test/material/about_test.dart | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index aa6eb6cbdb..6e4565802a 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -889,7 +889,11 @@ class _PackageLicensePageState extends State<_PackageLicensePage> { // A Scrollbar is built-in below. behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), child: Scrollbar( - child: ListView(padding: padding, children: listWidgets), + child: ListView( + primary: true, + padding: padding, + children: listWidgets, + ), ), ), ), diff --git a/packages/flutter/test/material/about_test.dart b/packages/flutter/test/material/about_test.dart index 9a4870b7ed..81da85f62b 100644 --- a/packages/flutter/test/material/about_test.dart +++ b/packages/flutter/test/material/about_test.dart @@ -913,6 +913,67 @@ void main() { }, variant: TargetPlatformVariant.all()); + testWidgets('ListView of license entries is primary', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/120710 + LicenseRegistry.addLicense(() { + return Stream.fromIterable([ + LicenseEntryWithLineBreaks( + ['AAA'], + // Add enough content to scroll + List.generate(500, (int index) => 'BBBB').join('\n'), + ), + ]); + }); + + await tester.pumpWidget( + MaterialApp( + title: 'Flutter Code Sample', + home: Scaffold( + body: Builder( + builder: (BuildContext context) => TextButton( + child: const Text('Show License Page'), + onPressed: () { + showLicensePage(context: context); + }, + ), + ), + ), + ) + ); + await tester.pumpAndSettle(); + + expect(find.text('Show License Page'), findsOneWidget); + await tester.tap(find.text('Show License Page')); + await tester.pumpAndSettle(); + + // Check for packages. + expect(find.text('AAA'), findsOneWidget); + // Check license is displayed after entering into license page for 'AAA'. + await tester.tap(find.text('AAA')); + await tester.pumpAndSettle(); + + // The inherited ScrollBehavior should not apply Scrollbars since they are + // already built in to the widget. + switch (debugDefaultTargetPlatformOverride) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.macOS: + case TargetPlatform.windows: + expect(find.byType(CupertinoScrollbar), findsNothing); + break; + case TargetPlatform.iOS: + expect(find.byType(CupertinoScrollbar), findsOneWidget); + break; + case null: + break; + } + expect(find.byType(Scrollbar), findsOneWidget); + expect(find.byType(RawScrollbar), findsNothing); + await tester.drag(find.byType(ListView), const Offset(0.0, 20.0)); + await tester.pumpAndSettle(); // No exception triggered. + }, variant: TargetPlatformVariant.all()); + testWidgets('LicensePage padding', (WidgetTester tester) async { const FlutterLogo logo = FlutterLogo();