Skip to content

Commit 2642a54

Browse files
authored
Fix LicensePage too much spacing padding when applicationVersion and applicationLegalese are empty (#101030)
1 parent 2d89866 commit 2642a54

File tree

2 files changed

+91
-11
lines changed

2 files changed

+91
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,21 @@ class _AboutProgram extends StatelessWidget {
493493
),
494494
if (icon != null)
495495
IconTheme(data: Theme.of(context).iconTheme, child: icon!),
496-
Text(
497-
version,
498-
style: Theme.of(context).textTheme.bodyText2,
499-
textAlign: TextAlign.center,
500-
),
501-
const SizedBox(height: _textVerticalSeparation),
502-
Text(
503-
legalese ?? '',
504-
style: Theme.of(context).textTheme.caption,
505-
textAlign: TextAlign.center,
506-
),
496+
if (version != '')
497+
Padding(
498+
padding: const EdgeInsets.only(bottom: _textVerticalSeparation),
499+
child: Text(
500+
version,
501+
style: Theme.of(context).textTheme.bodyText2,
502+
textAlign: TextAlign.center,
503+
),
504+
),
505+
if (legalese != null && legalese != '')
506+
Text(
507+
legalese!,
508+
style: Theme.of(context).textTheme.caption,
509+
textAlign: TextAlign.center,
510+
),
507511
const SizedBox(height: _textVerticalSeparation),
508512
Text(
509513
'Powered by Flutter',

packages/flutter/test/material/about_test.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,82 @@ void main() {
881881
expect(find.byType(RawScrollbar), findsNothing);
882882

883883
}, variant: TargetPlatformVariant.all());
884+
885+
testWidgets('LicensePage padding', (WidgetTester tester) async {
886+
const FlutterLogo logo = FlutterLogo();
887+
888+
await tester.pumpWidget(
889+
const MaterialApp(
890+
title: 'Pirate app',
891+
home: Center(
892+
child: LicensePage(
893+
applicationName: 'LicensePage test app',
894+
applicationIcon: logo,
895+
applicationVersion: '0.1.2',
896+
applicationLegalese: 'I am the very model of a modern major general.',
897+
),
898+
),
899+
),
900+
);
901+
902+
final Finder appName = find.text('LicensePage test app');
903+
final Finder appIcon = find.byType(FlutterLogo);
904+
final Finder appVersion = find.text('0.1.2');
905+
final Finder appLegalese = find.text('I am the very model of a modern major general.');
906+
final Finder appPowered = find.text('Powered by Flutter');
907+
908+
expect(appName, findsOneWidget);
909+
expect(appIcon, findsOneWidget);
910+
expect(appVersion, findsOneWidget);
911+
expect(appLegalese, findsOneWidget);
912+
expect(appPowered, findsOneWidget);
913+
914+
// Bottom padding is applied to the app version and app legalese text.
915+
final double appNameBottomPadding = tester.getTopLeft(appIcon).dy - tester.getBottomLeft(appName).dy;
916+
expect(appNameBottomPadding, 0.0);
917+
918+
final double appIconBottomPadding = tester.getTopLeft(appVersion).dy - tester.getBottomLeft(appIcon).dy;
919+
expect(appIconBottomPadding, 0.0);
920+
921+
final double appVersionBottomPadding = tester.getTopLeft(appLegalese).dy - tester.getBottomLeft(appVersion).dy;
922+
expect(appVersionBottomPadding, 18.0);
923+
924+
final double appLegaleseBottomPadding = tester.getTopLeft(appPowered).dy - tester.getBottomLeft(appLegalese).dy;
925+
expect(appLegaleseBottomPadding, 18.0);
926+
});
927+
928+
testWidgets('LicensePage has no extra padding between app icon and app powered text', (WidgetTester tester) async {
929+
// This is a regression test for https://github.com/flutter/flutter/issues/99559
930+
931+
const FlutterLogo logo = FlutterLogo();
932+
933+
await tester.pumpWidget(
934+
const MaterialApp(
935+
title: 'Pirate app',
936+
home: Center(
937+
child: LicensePage(
938+
applicationIcon: logo,
939+
),
940+
),
941+
),
942+
);
943+
944+
final Finder appName = find.text('LicensePage test app');
945+
final Finder appIcon = find.byType(FlutterLogo);
946+
final Finder appVersion = find.text('0.1.2');
947+
final Finder appLegalese = find.text('I am the very model of a modern major general.');
948+
final Finder appPowered = find.text('Powered by Flutter');
949+
950+
expect(appName, findsNothing);
951+
expect(appIcon, findsOneWidget);
952+
expect(appVersion, findsNothing);
953+
expect(appLegalese, findsNothing);
954+
expect(appPowered, findsOneWidget);
955+
956+
// Padding between app icon and app powered text.
957+
final double appIconBottomPadding = tester.getTopLeft(appPowered).dy - tester.getBottomLeft(appIcon).dy;
958+
expect(appIconBottomPadding, 18.0);
959+
});
884960
}
885961

886962
class FakeLicenseEntry extends LicenseEntry {

0 commit comments

Comments
 (0)