Unverified Commit 709b26d0 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Add `surfaceTintColor` to `NavigationBar` (#102628)

parent 4ffc41ad
...@@ -25,11 +25,9 @@ class _TokenDefaultsM3 extends NavigationBarThemeData { ...@@ -25,11 +25,9 @@ class _TokenDefaultsM3 extends NavigationBarThemeData {
late final ColorScheme _colors = Theme.of(context).colorScheme; late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme; late final TextTheme _textTheme = Theme.of(context).textTheme;
// With Material 3, the NavigationBar uses an overlay blend for the @override Color? get backgroundColor => ${componentColor("md.comp.navigation-bar.container")};
// default color regardless of light/dark mode. This should be handled
// in the Material widget based off of elevation, but for now we will do @override Color? get surfaceTintColor => ${color("md.comp.navigation-bar.container.surface-tint-layer.color")};
// it here in the defaults.
@override Color? get backgroundColor => ElevationOverlay.colorWithOverlay(${componentColor("md.comp.navigation-bar.container")}, _colors.primary, ${elevation("md.comp.navigation-bar.container")});
@override MaterialStateProperty<IconThemeData?>? get iconTheme { @override MaterialStateProperty<IconThemeData?>? get iconTheme {
return MaterialStateProperty.resolveWith((Set<MaterialState> states) { return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
......
...@@ -59,6 +59,7 @@ class NavigationBar extends StatelessWidget { ...@@ -59,6 +59,7 @@ class NavigationBar extends StatelessWidget {
required this.destinations, required this.destinations,
this.onDestinationSelected, this.onDestinationSelected,
this.backgroundColor, this.backgroundColor,
this.surfaceTintColor,
this.elevation, this.elevation,
this.height, this.height,
this.labelBehavior, this.labelBehavior,
...@@ -95,10 +96,20 @@ class NavigationBar extends StatelessWidget { ...@@ -95,10 +96,20 @@ class NavigationBar extends StatelessWidget {
/// The color of the [NavigationBar] itself. /// The color of the [NavigationBar] itself.
/// ///
/// If null, [NavigationBarThemeData.backgroundColor] is used. If that /// If null, [NavigationBarThemeData.backgroundColor] is used. If that
/// is also null, the default blends [ColorScheme.surface] and /// is also null, then if [ThemeData.useMaterial3] is true, the value is
/// [ColorScheme.onSurface] using an [ElevationOverlay]. /// [ColorScheme.surface]. If that is false, the default blends [ColorScheme.surface]
/// and [ColorScheme.onSurface] using an [ElevationOverlay].
final Color? backgroundColor; final Color? backgroundColor;
/// The color used as an overlay on [backgroundColor] to indicate elevation.
///
/// If null, [NavigationBarThemeData.surfaceTintColor] is used. If that
/// is also null, the default value is [ColorScheme.surfaceTint].
///
/// See [Material.surfaceTintColor] for more details on how this
/// overlay is applied.
final Color? surfaceTintColor;
/// The elevation of the [NavigationBar] itself. /// The elevation of the [NavigationBar] itself.
/// ///
/// If null, [NavigationBarThemeData.elevation] is used. If that /// If null, [NavigationBarThemeData.elevation] is used. If that
...@@ -152,6 +163,7 @@ class NavigationBar extends StatelessWidget { ...@@ -152,6 +163,7 @@ class NavigationBar extends StatelessWidget {
color: backgroundColor color: backgroundColor
?? navigationBarTheme.backgroundColor ?? navigationBarTheme.backgroundColor
?? defaults.backgroundColor!, ?? defaults.backgroundColor!,
surfaceTintColor: surfaceTintColor ?? navigationBarTheme.surfaceTintColor ?? defaults.surfaceTintColor,
elevation: elevation ?? navigationBarTheme.elevation ?? defaults.elevation!, elevation: elevation ?? navigationBarTheme.elevation ?? defaults.elevation!,
child: SafeArea( child: SafeArea(
child: SizedBox( child: SizedBox(
...@@ -1214,11 +1226,9 @@ class _TokenDefaultsM3 extends NavigationBarThemeData { ...@@ -1214,11 +1226,9 @@ class _TokenDefaultsM3 extends NavigationBarThemeData {
late final ColorScheme _colors = Theme.of(context).colorScheme; late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme; late final TextTheme _textTheme = Theme.of(context).textTheme;
// With Material 3, the NavigationBar uses an overlay blend for the @override Color? get backgroundColor => _colors.surface;
// default color regardless of light/dark mode. This should be handled
// in the Material widget based off of elevation, but for now we will do @override Color? get surfaceTintColor => _colors.surfaceTint;
// it here in the defaults.
@override Color? get backgroundColor => ElevationOverlay.colorWithOverlay(_colors.surface, _colors.primary, 3.0);
@override MaterialStateProperty<IconThemeData?>? get iconTheme { @override MaterialStateProperty<IconThemeData?>? get iconTheme {
return MaterialStateProperty.resolveWith((Set<MaterialState> states) { return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
......
...@@ -41,6 +41,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -41,6 +41,7 @@ class NavigationBarThemeData with Diagnosticable {
const NavigationBarThemeData({ const NavigationBarThemeData({
this.height, this.height,
this.backgroundColor, this.backgroundColor,
this.surfaceTintColor,
this.elevation, this.elevation,
this.indicatorColor, this.indicatorColor,
this.indicatorShape, this.indicatorShape,
...@@ -55,6 +56,9 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -55,6 +56,9 @@ class NavigationBarThemeData with Diagnosticable {
/// Overrides the default value of [NavigationBar.backgroundColor]. /// Overrides the default value of [NavigationBar.backgroundColor].
final Color? backgroundColor; final Color? backgroundColor;
/// Overrides the default value of [NavigationBar.surfaceTintColor].
final Color? surfaceTintColor;
/// Overrides the default value of [NavigationBar.elevation]. /// Overrides the default value of [NavigationBar.elevation].
final double? elevation; final double? elevation;
...@@ -85,6 +89,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -85,6 +89,7 @@ class NavigationBarThemeData with Diagnosticable {
NavigationBarThemeData copyWith({ NavigationBarThemeData copyWith({
double? height, double? height,
Color? backgroundColor, Color? backgroundColor,
Color? surfaceTintColor,
double? elevation, double? elevation,
Color? indicatorColor, Color? indicatorColor,
ShapeBorder? indicatorShape, ShapeBorder? indicatorShape,
...@@ -95,6 +100,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -95,6 +100,7 @@ class NavigationBarThemeData with Diagnosticable {
return NavigationBarThemeData( return NavigationBarThemeData(
height: height ?? this.height, height: height ?? this.height,
backgroundColor: backgroundColor ?? this.backgroundColor, backgroundColor: backgroundColor ?? this.backgroundColor,
surfaceTintColor: surfaceTintColor ?? this.surfaceTintColor,
elevation: elevation ?? this.elevation, elevation: elevation ?? this.elevation,
indicatorColor: indicatorColor ?? this.indicatorColor, indicatorColor: indicatorColor ?? this.indicatorColor,
indicatorShape: indicatorShape ?? this.indicatorShape, indicatorShape: indicatorShape ?? this.indicatorShape,
...@@ -116,6 +122,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -116,6 +122,7 @@ class NavigationBarThemeData with Diagnosticable {
return NavigationBarThemeData( return NavigationBarThemeData(
height: lerpDouble(a?.height, b?.height, t), height: lerpDouble(a?.height, b?.height, t),
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t), elevation: lerpDouble(a?.elevation, b?.elevation, t),
indicatorColor: Color.lerp(a?.indicatorColor, b?.indicatorColor, t), indicatorColor: Color.lerp(a?.indicatorColor, b?.indicatorColor, t),
indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t), indicatorShape: ShapeBorder.lerp(a?.indicatorShape, b?.indicatorShape, t),
...@@ -129,6 +136,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -129,6 +136,7 @@ class NavigationBarThemeData with Diagnosticable {
int get hashCode => Object.hash( int get hashCode => Object.hash(
height, height,
backgroundColor, backgroundColor,
surfaceTintColor,
elevation, elevation,
indicatorColor, indicatorColor,
indicatorShape, indicatorShape,
...@@ -146,6 +154,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -146,6 +154,7 @@ class NavigationBarThemeData with Diagnosticable {
return other is NavigationBarThemeData return other is NavigationBarThemeData
&& other.height == height && other.height == height
&& other.backgroundColor == backgroundColor && other.backgroundColor == backgroundColor
&& other.surfaceTintColor == surfaceTintColor
&& other.elevation == elevation && other.elevation == elevation
&& other.indicatorColor == indicatorColor && other.indicatorColor == indicatorColor
&& other.indicatorShape == indicatorShape && other.indicatorShape == indicatorShape
...@@ -159,6 +168,7 @@ class NavigationBarThemeData with Diagnosticable { ...@@ -159,6 +168,7 @@ class NavigationBarThemeData with Diagnosticable {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(DoubleProperty('height', height, defaultValue: null)); properties.add(DoubleProperty('height', height, defaultValue: null));
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null));
properties.add(ColorProperty('surfaceTintColor', surfaceTintColor, defaultValue: null));
properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); properties.add(DoubleProperty('elevation', elevation, defaultValue: null));
properties.add(ColorProperty('indicatorColor', indicatorColor, defaultValue: null)); properties.add(ColorProperty('indicatorColor', indicatorColor, defaultValue: null));
properties.add(DiagnosticsProperty<ShapeBorder>('indicatorShape', indicatorShape, defaultValue: null)); properties.add(DiagnosticsProperty<ShapeBorder>('indicatorShape', indicatorShape, defaultValue: null));
......
...@@ -257,6 +257,7 @@ void main() { ...@@ -257,6 +257,7 @@ void main() {
); );
expect(_getMaterial(tester).color, const Color(0xffeaeaea)); expect(_getMaterial(tester).color, const Color(0xffeaeaea));
expect(_getMaterial(tester).surfaceTintColor, null);
expect(_getMaterial(tester).elevation, 0); expect(_getMaterial(tester).elevation, 0);
expect(tester.getSize(find.byType(NavigationBar)).height, 80); expect(tester.getSize(find.byType(NavigationBar)).height, 80);
expect(_indicator(tester)?.color, const Color(0x3d2196f3)); expect(_indicator(tester)?.color, const Color(0x3d2196f3));
...@@ -284,7 +285,8 @@ void main() { ...@@ -284,7 +285,8 @@ void main() {
), ),
); );
expect(_getMaterial(tester).color, const Color(0xffecf6fe)); expect(_getMaterial(tester).color, ThemeData().colorScheme.surface);
expect(_getMaterial(tester).surfaceTintColor, ThemeData().colorScheme.surfaceTint);
expect(_getMaterial(tester).elevation, 3); expect(_getMaterial(tester).elevation, 3);
expect(tester.getSize(find.byType(NavigationBar)).height, 80); expect(tester.getSize(find.byType(NavigationBar)).height, 80);
expect(_indicator(tester)?.color, const Color(0xff2196f3)); expect(_indicator(tester)?.color, const Color(0xff2196f3));
......
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