Skip to content

Code Comments Error in "flutter/packages/flutter/lib/src/material /navigation_bar.dart" #162592

@gaspardruan

Description

@gaspardruan

Flutter version:

Flutter 3.27.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c519ee916e (13 days ago) • 2025-01-21 10:32:23 -0800
Engine • revision e672b006cb
Tools • Dart 3.6.1 • DevTools 2.40.2

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<TextStyle?>? get labelTextStyle {
    return MaterialStateProperty.resolveWith((Set<MaterialState> 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.

Conclusion

Rectify the comments as below:

  /// 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]
  /// when [ThemeData.useMaterial3] is false, and use [TextTheme.labelMedium]
  /// when [ThemeData.useMaterial3] is true.
  final String label;

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions