Unverified Commit 7d52c2c4 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Added AppBarTheme shape property (#86372)

parent 2900347a
......@@ -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<AppBar> {
shadowColor: widget.shadowColor
?? appBarTheme.shadowColor
?? _defaultShadowColor,
shape: widget.shape,
shape: widget.shape ?? appBarTheme.shape,
child: Semantics(
explicitChildNodes: true,
child: appBar,
......
......@@ -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<double>('elevation', elevation, defaultValue: null));
properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null));
properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null));
properties.add(DiagnosticsProperty<IconThemeData>('iconTheme', iconTheme, defaultValue: null));
properties.add(DiagnosticsProperty<IconThemeData>('actionsIconTheme', actionsIconTheme, defaultValue: null));
properties.add(DiagnosticsProperty<TextTheme>('textTheme', textTheme, defaultValue: null));
......
......@@ -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),
......
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