From f219bbac551472704e4610b90d8447c7b92b1cc0 Mon Sep 17 00:00:00 2001 From: Gaspard Ruan <1039553124@qq.com> Date: Thu, 6 Feb 2025 19:40:19 +0800 Subject: [PATCH] Update code comments for navigation_bar.dart (#162596) Fixes https://github.com/flutter/flutter/issues/162592 ### Comments error: ``` class NavigationDestination extends StatelessWidget { ... /// The text label that appears below the icon of this /// [NavigationDestination]. /// /// The accompanying [Text] widget will use /// [NavigationBarThemeData.labelTextStyle]. If this are null, the default /// text style would use [TextTheme.labelSmall] with [ColorScheme.onSurface]. final String label; ... } ``` `If this are null, the default text style would use [TextTheme.labelSmall]` is wrong. Actually, This is right in material2, but wrong in material3. I have dived into `_NavigationBarDefaultsM3`, I found this: ``` class _NavigationBarDefaultsM3 extends NavigationBarThemeData { ... @override MaterialStateProperty? get labelTextStyle { return MaterialStateProperty.resolveWith((Set states) { final TextStyle style = _textTheme.labelMedium!; return style.apply( color: states.contains(MaterialState.disabled) ? _colors.onSurfaceVariant.withOpacity(0.38) : states.contains(MaterialState.selected) ? _colors.onSurface : _colors.onSurfaceVariant ); }); } ... } ``` **The default text style would use [TextTheme.labelMedium] in Material3.** ### Changes Just clarify the doc comments above.[test-exempt] ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Taha Tesser --- packages/flutter/lib/src/material/navigation_bar.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/navigation_bar.dart b/packages/flutter/lib/src/material/navigation_bar.dart index d24344bb7a..5f67e86292 100644 --- a/packages/flutter/lib/src/material/navigation_bar.dart +++ b/packages/flutter/lib/src/material/navigation_bar.dart @@ -385,9 +385,12 @@ class NavigationDestination extends StatelessWidget { /// The text label that appears below the icon of this /// [NavigationDestination]. /// - /// The accompanying [Text] widget will use - /// [NavigationBarThemeData.labelTextStyle]. If this are null, the default - /// text style would use [TextTheme.labelSmall] with [ColorScheme.onSurface]. + /// The accompanying [Text] widget will use [NavigationBarThemeData.labelTextStyle]. + /// If this is null, the default text style will use [TextTheme.labelMedium] with + /// [ColorScheme.onSurface] when the destination is selected and + /// [ColorScheme.onSurfaceVariant] when the destination is unselected. If + /// [ThemeData.useMaterial3] is false, then the default text style will use + /// [TextTheme.labelSmall] with [ColorScheme.onSurface]. final String label; /// The text to display in the tooltip for this [NavigationDestination], when