diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index acb3f2e377..544a45b245 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -472,7 +472,12 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { final Color? shadowColor; /// {@template flutter.material.appbar.shape} - /// The shape of the app bar's material's shape as well as its shadow. + /// The shape of the app bar's [Material] as well as its shadow. + /// + /// If this property is null, then [AppBarTheme.shape] of + /// [ThemeData.appBarTheme] is used. Both properties default to null. + /// If both properties are null then the shape of the app bar's [Material] + /// is just a simple rectangle. /// /// A shadow is only displayed if the [elevation] is greater than /// zero. @@ -1129,7 +1134,7 @@ class _AppBarState extends State { shadowColor: widget.shadowColor ?? appBarTheme.shadowColor ?? _defaultShadowColor, - shape: widget.shape, + shape: widget.shape ?? appBarTheme.shape, child: Semantics( explicitChildNodes: true, child: appBar, diff --git a/packages/flutter/lib/src/material/app_bar_theme.dart b/packages/flutter/lib/src/material/app_bar_theme.dart index aa8ce52602..f0eccfc07f 100644 --- a/packages/flutter/lib/src/material/app_bar_theme.dart +++ b/packages/flutter/lib/src/material/app_bar_theme.dart @@ -38,6 +38,7 @@ class AppBarTheme with Diagnosticable { this.foregroundColor, this.elevation, this.shadowColor, + this.shape, this.iconTheme, this.actionsIconTheme, @Deprecated( @@ -124,6 +125,10 @@ class AppBarTheme with Diagnosticable { /// descendant widgets. final Color? shadowColor; + /// Overrides the default value for [AppBar.shape] in all + /// descendant widgets. + final ShapeBorder? shape; + /// Overrides the default value of [AppBar.iconTheme] in all /// descendant [AppBar] widgets. /// @@ -229,6 +234,7 @@ class AppBarTheme with Diagnosticable { Color? foregroundColor, double? elevation, Color? shadowColor, + ShapeBorder? shape, IconThemeData? iconTheme, TextTheme? textTheme, bool? centerTitle, @@ -249,6 +255,7 @@ class AppBarTheme with Diagnosticable { foregroundColor: foregroundColor ?? this.foregroundColor, elevation: elevation ?? this.elevation, shadowColor: shadowColor ?? this.shadowColor, + shape: shape ?? this.shape, iconTheme: iconTheme ?? this.iconTheme, actionsIconTheme: actionsIconTheme ?? this.actionsIconTheme, textTheme: textTheme ?? this.textTheme, @@ -280,6 +287,7 @@ class AppBarTheme with Diagnosticable { foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), elevation: lerpDouble(a?.elevation, b?.elevation, t), shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), + shape: ShapeBorder.lerp(a?.shape, b?.shape, t), iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t), actionsIconTheme: IconThemeData.lerp(a?.actionsIconTheme, b?.actionsIconTheme, t), textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t), @@ -301,6 +309,7 @@ class AppBarTheme with Diagnosticable { foregroundColor, elevation, shadowColor, + shape, iconTheme, actionsIconTheme, textTheme, @@ -326,6 +335,7 @@ class AppBarTheme with Diagnosticable { && other.foregroundColor == foregroundColor && other.elevation == elevation && other.shadowColor == shadowColor + && other.shape == shape && other.iconTheme == iconTheme && other.actionsIconTheme == actionsIconTheme && other.textTheme == textTheme @@ -346,6 +356,7 @@ class AppBarTheme with Diagnosticable { properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); properties.add(DiagnosticsProperty('elevation', elevation, defaultValue: null)); properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); + properties.add(DiagnosticsProperty('shape', shape, defaultValue: null)); properties.add(DiagnosticsProperty('iconTheme', iconTheme, defaultValue: null)); properties.add(DiagnosticsProperty('actionsIconTheme', actionsIconTheme, defaultValue: null)); properties.add(DiagnosticsProperty('textTheme', textTheme, defaultValue: null)); diff --git a/packages/flutter/test/material/app_bar_theme_test.dart b/packages/flutter/test/material/app_bar_theme_test.dart index fd8565fc77..dd8be5d402 100644 --- a/packages/flutter/test/material/app_bar_theme_test.dart +++ b/packages/flutter/test/material/app_bar_theme_test.dart @@ -37,6 +37,7 @@ void main() { expect(widget.color, Colors.blue); expect(widget.elevation, 4.0); expect(widget.shadowColor, Colors.black); + expect(widget.shape, null); expect(iconTheme.data, const IconThemeData(color: Colors.white)); expect(actionsIconTheme.data, const IconThemeData(color: Colors.white)); expect(actionIconText.text.style!.color, Colors.white); @@ -72,6 +73,7 @@ void main() { expect(widget.color, appBarTheme.backgroundColor); expect(widget.elevation, appBarTheme.elevation); expect(widget.shadowColor, appBarTheme.shadowColor); + expect(widget.shape, const StadiumBorder()); expect(iconTheme.data, appBarTheme.iconTheme); expect(actionsIconTheme.data, appBarTheme.actionsIconTheme); expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color); @@ -131,6 +133,7 @@ void main() { const Color color = Colors.orange; const double elevation = 3.0; const Color shadowColor = Colors.red; + const ShapeBorder shape = RoundedRectangleBorder(); const IconThemeData iconThemeData = IconThemeData(color: Colors.green); const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.lightBlue); const TextStyle toolbarTextStyle = TextStyle(color: Colors.pink); @@ -138,7 +141,9 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: ThemeData.from(colorScheme: const ColorScheme.light()), + theme: ThemeData.from(colorScheme: const ColorScheme.light()).copyWith( + appBarTheme: _appBarTheme(), + ), home: Scaffold( appBar: AppBar( backgroundColor: color, @@ -146,6 +151,7 @@ void main() { systemOverlayStyle: systemOverlayStyle, elevation: elevation, shadowColor: shadowColor, + shape: shape, iconTheme: iconThemeData, actionsIconTheme: actionsIconThemeData, toolbarTextStyle: toolbarTextStyle, @@ -168,6 +174,7 @@ void main() { expect(widget.color, color); expect(widget.elevation, elevation); expect(widget.shadowColor, shadowColor); + expect(widget.shape, shape); expect(iconTheme.data, iconThemeData); expect(actionsIconTheme.data, actionsIconThemeData); expect(actionIconText.text.style!.color, actionsIconThemeData.color); @@ -525,6 +532,7 @@ AppBarTheme _appBarTheme() { backgroundColor: backgroundColor, elevation: elevation, shadowColor: shadowColor, + shape: StadiumBorder(), iconTheme: iconThemeData, toolbarHeight: 96, toolbarTextStyle: TextStyle(color: Colors.yellow),