Skip to content

Commit 4ae5252

Browse files
authored
Fix license page crash (#120728)
1 parent 911b137 commit 4ae5252

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,11 @@ class _PackageLicensePageState extends State<_PackageLicensePage> {
889889
// A Scrollbar is built-in below.
890890
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
891891
child: Scrollbar(
892-
child: ListView(padding: padding, children: listWidgets),
892+
child: ListView(
893+
primary: true,
894+
padding: padding,
895+
children: listWidgets,
896+
),
893897
),
894898
),
895899
),

packages/flutter/test/material/about_test.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,67 @@ void main() {
913913

914914
}, variant: TargetPlatformVariant.all());
915915

916+
testWidgets('ListView of license entries is primary', (WidgetTester tester) async {
917+
// Regression test for https://github.com/flutter/flutter/issues/120710
918+
LicenseRegistry.addLicense(() {
919+
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
920+
LicenseEntryWithLineBreaks(
921+
<String>['AAA'],
922+
// Add enough content to scroll
923+
List<String>.generate(500, (int index) => 'BBBB').join('\n'),
924+
),
925+
]);
926+
});
927+
928+
await tester.pumpWidget(
929+
MaterialApp(
930+
title: 'Flutter Code Sample',
931+
home: Scaffold(
932+
body: Builder(
933+
builder: (BuildContext context) => TextButton(
934+
child: const Text('Show License Page'),
935+
onPressed: () {
936+
showLicensePage(context: context);
937+
},
938+
),
939+
),
940+
),
941+
)
942+
);
943+
await tester.pumpAndSettle();
944+
945+
expect(find.text('Show License Page'), findsOneWidget);
946+
await tester.tap(find.text('Show License Page'));
947+
await tester.pumpAndSettle();
948+
949+
// Check for packages.
950+
expect(find.text('AAA'), findsOneWidget);
951+
// Check license is displayed after entering into license page for 'AAA'.
952+
await tester.tap(find.text('AAA'));
953+
await tester.pumpAndSettle();
954+
955+
// The inherited ScrollBehavior should not apply Scrollbars since they are
956+
// already built in to the widget.
957+
switch (debugDefaultTargetPlatformOverride) {
958+
case TargetPlatform.android:
959+
case TargetPlatform.fuchsia:
960+
case TargetPlatform.linux:
961+
case TargetPlatform.macOS:
962+
case TargetPlatform.windows:
963+
expect(find.byType(CupertinoScrollbar), findsNothing);
964+
break;
965+
case TargetPlatform.iOS:
966+
expect(find.byType(CupertinoScrollbar), findsOneWidget);
967+
break;
968+
case null:
969+
break;
970+
}
971+
expect(find.byType(Scrollbar), findsOneWidget);
972+
expect(find.byType(RawScrollbar), findsNothing);
973+
await tester.drag(find.byType(ListView), const Offset(0.0, 20.0));
974+
await tester.pumpAndSettle(); // No exception triggered.
975+
}, variant: TargetPlatformVariant.all());
976+
916977
testWidgets('LicensePage padding', (WidgetTester tester) async {
917978
const FlutterLogo logo = FlutterLogo();
918979

0 commit comments

Comments
 (0)