diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index f85568c8fd..50ca6a4bea 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -301,14 +301,20 @@ void showLicensePage({ String? applicationLegalese, bool useRootNavigator = false, }) { + final CapturedThemes themes = InheritedTheme.capture( + from: context, + to: Navigator.of(context, rootNavigator: useRootNavigator).context, + ); Navigator.of(context, rootNavigator: useRootNavigator).push( MaterialPageRoute( builder: - (BuildContext context) => LicensePage( - applicationName: applicationName, - applicationVersion: applicationVersion, - applicationIcon: applicationIcon, - applicationLegalese: applicationLegalese, + (BuildContext context) => themes.wrap( + LicensePage( + applicationName: applicationName, + applicationVersion: applicationVersion, + applicationIcon: applicationIcon, + applicationLegalese: applicationLegalese, + ), ), ), ); diff --git a/packages/flutter/test/material/about_test.dart b/packages/flutter/test/material/about_test.dart index 28327366b6..1c5e602142 100644 --- a/packages/flutter/test/material/about_test.dart +++ b/packages/flutter/test/material/about_test.dart @@ -1851,6 +1851,43 @@ void main() { expect(find.byType(AlertDialog), findsNothing); } }); + + testWidgets('showLicensePage inherits ambient Theme', (WidgetTester tester) async { + final ThemeData theme = ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: const Color(0XFFFF0000)), + ); + + await tester.pumpWidget( + MaterialApp( + home: Theme( + data: theme, + child: Builder( + builder: + (BuildContext context) => ElevatedButton( + onPressed: () { + showAboutDialog( + context: context, + applicationName: 'Sample Test', + applicationVersion: 'v1.0.0', // Version of the app + ); + }, + child: const Text('Show About Dialog'), + ), + ), + ), + ), + ); + + // Open the dialog. + await tester.tap(find.byType(ElevatedButton)); + await tester.pumpAndSettle(); + + await tester.tap(find.text('View licenses')); + await tester.pumpAndSettle(); + + final ThemeData licensePageTheme = Theme.of(tester.element(find.text('Powered by Flutter'))); + expect(theme.colorScheme.primary, licensePageTheme.colorScheme.primary); + }); } class FakeLicenseEntry extends LicenseEntry {