Commit 0e7cfc1e authored by Hiroki Matsue's avatar Hiroki Matsue Committed by Shi-Hao Hong

Add missing [applicationIcon] property to LicensePage widget (#34906)

* Add missing [applicationIcon] property to LicensePage widget
parent 4e973adc
...@@ -192,6 +192,7 @@ void showLicensePage({ ...@@ -192,6 +192,7 @@ void showLicensePage({
builder: (BuildContext context) => LicensePage( builder: (BuildContext context) => LicensePage(
applicationName: applicationName, applicationName: applicationName,
applicationVersion: applicationVersion, applicationVersion: applicationVersion,
applicationIcon: applicationIcon,
applicationLegalese: applicationLegalese, applicationLegalese: applicationLegalese,
) )
)); ));
...@@ -275,7 +276,7 @@ class AboutDialog extends StatelessWidget { ...@@ -275,7 +276,7 @@ class AboutDialog extends StatelessWidget {
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
if (icon != null) IconTheme(data: const IconThemeData(size: 48.0), child: icon), if (icon != null) IconTheme(data: Theme.of(context).iconTheme, child: icon),
Expanded( Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0), padding: const EdgeInsets.symmetric(horizontal: 24.0),
...@@ -341,6 +342,7 @@ class LicensePage extends StatefulWidget { ...@@ -341,6 +342,7 @@ class LicensePage extends StatefulWidget {
Key key, Key key,
this.applicationName, this.applicationName,
this.applicationVersion, this.applicationVersion,
this.applicationIcon,
this.applicationLegalese, this.applicationLegalese,
}) : super(key: key); }) : super(key: key);
...@@ -357,6 +359,14 @@ class LicensePage extends StatefulWidget { ...@@ -357,6 +359,14 @@ class LicensePage extends StatefulWidget {
/// Defaults to the empty string. /// Defaults to the empty string.
final String applicationVersion; final String applicationVersion;
/// The icon to show below the application name.
///
/// By default no icon is shown.
///
/// Typically this will be an [ImageIcon] widget. It should honor the
/// [IconTheme]'s [IconThemeData.size].
final Widget applicationIcon;
/// A string to show in small print. /// A string to show in small print.
/// ///
/// Typically this is a copyright notice. /// Typically this is a copyright notice.
...@@ -455,6 +465,7 @@ class _LicensePageState extends State<LicensePage> { ...@@ -455,6 +465,7 @@ class _LicensePageState extends State<LicensePage> {
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final String name = widget.applicationName ?? _defaultApplicationName(context); final String name = widget.applicationName ?? _defaultApplicationName(context);
final String version = widget.applicationVersion ?? _defaultApplicationVersion(context); final String version = widget.applicationVersion ?? _defaultApplicationVersion(context);
final Widget icon = widget.applicationIcon ?? _defaultApplicationIcon(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context); final MaterialLocalizations localizations = MaterialLocalizations.of(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
...@@ -474,6 +485,7 @@ class _LicensePageState extends State<LicensePage> { ...@@ -474,6 +485,7 @@ class _LicensePageState extends State<LicensePage> {
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0), padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
children: <Widget>[ children: <Widget>[
Text(name, style: Theme.of(context).textTheme.headline, textAlign: TextAlign.center), Text(name, style: Theme.of(context).textTheme.headline, textAlign: TextAlign.center),
if (icon != null) IconTheme(data: Theme.of(context).iconTheme, child: icon),
Text(version, style: Theme.of(context).textTheme.body1, textAlign: TextAlign.center), Text(version, style: Theme.of(context).textTheme.body1, textAlign: TextAlign.center),
Container(height: 18.0), Container(height: 18.0),
Text(widget.applicationLegalese ?? '', style: Theme.of(context).textTheme.caption, textAlign: TextAlign.center), Text(widget.applicationLegalese ?? '', style: Theme.of(context).textTheme.caption, textAlign: TextAlign.center),
......
...@@ -14,6 +14,8 @@ void main() { ...@@ -14,6 +14,8 @@ void main() {
}); });
testWidgets('AboutListTile control test', (WidgetTester tester) async { testWidgets('AboutListTile control test', (WidgetTester tester) async {
const FlutterLogo logo = FlutterLogo();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
title: 'Pirate app', title: 'Pirate app',
...@@ -26,7 +28,7 @@ void main() { ...@@ -26,7 +28,7 @@ void main() {
children: const <Widget>[ children: const <Widget>[
AboutListTile( AboutListTile(
applicationVersion: '0.1.2', applicationVersion: '0.1.2',
applicationIcon: FlutterLogo(), applicationIcon: logo,
applicationLegalese: 'I am the very model of a modern major general.', applicationLegalese: 'I am the very model of a modern major general.',
aboutBoxChildren: <Widget>[ aboutBoxChildren: <Widget>[
Text('About box'), Text('About box'),
...@@ -41,6 +43,11 @@ void main() { ...@@ -41,6 +43,11 @@ void main() {
expect(find.text('About Pirate app'), findsNothing); expect(find.text('About Pirate app'), findsNothing);
expect(find.text('0.1.2'), findsNothing); expect(find.text('0.1.2'), findsNothing);
expect(find.byWidget(logo), findsNothing);
expect(
find.text('I am the very model of a modern major general.'),
findsNothing,
);
expect(find.text('About box'), findsNothing); expect(find.text('About box'), findsNothing);
await tester.tap(find.byType(IconButton)); await tester.tap(find.byType(IconButton));
...@@ -48,6 +55,11 @@ void main() { ...@@ -48,6 +55,11 @@ void main() {
expect(find.text('About Pirate app'), findsOneWidget); expect(find.text('About Pirate app'), findsOneWidget);
expect(find.text('0.1.2'), findsNothing); expect(find.text('0.1.2'), findsNothing);
expect(find.byWidget(logo), findsNothing);
expect(
find.text('I am the very model of a modern major general.'),
findsNothing,
);
expect(find.text('About box'), findsNothing); expect(find.text('About box'), findsNothing);
await tester.tap(find.text('About Pirate app')); await tester.tap(find.text('About Pirate app'));
...@@ -55,17 +67,29 @@ void main() { ...@@ -55,17 +67,29 @@ void main() {
expect(find.text('About Pirate app'), findsOneWidget); expect(find.text('About Pirate app'), findsOneWidget);
expect(find.text('0.1.2'), findsOneWidget); expect(find.text('0.1.2'), findsOneWidget);
expect(find.byWidget(logo), findsOneWidget);
expect(
find.text('I am the very model of a modern major general.'),
findsOneWidget,
);
expect(find.text('About box'), findsOneWidget); expect(find.text('About box'), findsOneWidget);
LicenseRegistry.addLicense(() { LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[ return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>[ 'Pirate package '], 'Pirate license'), const LicenseEntryWithLineBreaks(<String>['Pirate package '], 'Pirate license'),
]); ]);
}); });
await tester.tap(find.text('VIEW LICENSES')); await tester.tap(find.text('VIEW LICENSES'));
await tester.pumpAndSettle(const Duration(milliseconds: 100)); await tester.pumpAndSettle(const Duration(milliseconds: 100));
expect(find.text('Pirate app'), findsOneWidget);
expect(find.text('0.1.2'), findsOneWidget);
expect(find.byWidget(logo), findsOneWidget);
expect(
find.text('I am the very model of a modern major general.'),
findsOneWidget,
);
expect(find.text('Pirate license'), findsOneWidget); expect(find.text('Pirate license'), findsOneWidget);
}, skip: isBrowser); }, skip: isBrowser);
...@@ -79,7 +103,7 @@ void main() { ...@@ -79,7 +103,7 @@ void main() {
expect(find.text('About flutter_tester'), findsOneWidget); expect(find.text('About flutter_tester'), findsOneWidget);
}); });
testWidgets('AboutListTile control test', (WidgetTester tester) async { testWidgets('LicensePage control test', (WidgetTester tester) async {
LicenseRegistry.addLicense(() { LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[ return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>['AAA'], 'BBB'), const LicenseEntryWithLineBreaks(<String>['AAA'], 'BBB'),
...@@ -88,7 +112,10 @@ void main() { ...@@ -88,7 +112,10 @@ void main() {
LicenseRegistry.addLicense(() { LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[ return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>['Another package'], 'Another license'), const LicenseEntryWithLineBreaks(
<String>['Another package'],
'Another license',
),
]); ]);
}); });
...@@ -113,6 +140,67 @@ void main() { ...@@ -113,6 +140,67 @@ void main() {
expect(find.text('Another license'), findsOneWidget); expect(find.text('Another license'), findsOneWidget);
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('LicensePage control test with all properties', (WidgetTester tester) async {
const FlutterLogo logo = FlutterLogo();
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(<String>['AAA'], 'BBB'),
]);
});
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromIterable(<LicenseEntry>[
const LicenseEntryWithLineBreaks(
<String>['Another package'],
'Another license',
),
]);
});
await tester.pumpWidget(
const MaterialApp(
title: 'Pirate app',
home: Center(
child: LicensePage(
applicationName: 'LicensePage test app',
applicationVersion: '0.1.2',
applicationIcon: logo,
applicationLegalese: 'I am the very model of a modern major general.',
),
),
),
);
expect(find.text('Pirate app'), findsNothing);
expect(find.text('LicensePage test app'), findsOneWidget);
expect(find.text('0.1.2'), findsOneWidget);
expect(find.byWidget(logo), findsOneWidget);
expect(
find.text('I am the very model of a modern major general.'),
findsOneWidget,
);
expect(find.text('AAA'), findsNothing);
expect(find.text('BBB'), findsNothing);
expect(find.text('Another package'), findsNothing);
expect(find.text('Another license'), findsNothing);
await tester.pumpAndSettle();
expect(find.text('Pirate app'), findsNothing);
expect(find.text('LicensePage test app'), findsOneWidget);
expect(find.text('0.1.2'), findsOneWidget);
expect(find.byWidget(logo), findsOneWidget);
expect(
find.text('I am the very model of a modern major general.'),
findsOneWidget,
);
expect(find.text('AAA'), findsOneWidget);
expect(find.text('BBB'), findsOneWidget);
expect(find.text('Another package'), findsOneWidget);
expect(find.text('Another license'), findsOneWidget);
}, skip: isBrowser);
testWidgets('LicensePage respects the notch', (WidgetTester tester) async { testWidgets('LicensePage respects the notch', (WidgetTester tester) async {
const double safeareaPadding = 27.0; const double safeareaPadding = 27.0;
...@@ -187,6 +275,16 @@ void main() { ...@@ -187,6 +275,16 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(licenseEntry.paragraphsCalled, true); expect(licenseEntry.paragraphsCalled, true);
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('LicensePage logic defaults to executable name for app name', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
title: 'flutter_tester',
home: Material(child: LicensePage()),
),
);
expect(find.text('flutter_tester'), findsOneWidget);
});
} }
class FakeLicenseEntry extends LicenseEntry { class FakeLicenseEntry extends LicenseEntry {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment