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 { ...@@ -472,7 +472,12 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
final Color? shadowColor; final Color? shadowColor;
/// {@template flutter.material.appbar.shape} /// {@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 /// A shadow is only displayed if the [elevation] is greater than
/// zero. /// zero.
...@@ -1129,7 +1134,7 @@ class _AppBarState extends State<AppBar> { ...@@ -1129,7 +1134,7 @@ class _AppBarState extends State<AppBar> {
shadowColor: widget.shadowColor shadowColor: widget.shadowColor
?? appBarTheme.shadowColor ?? appBarTheme.shadowColor
?? _defaultShadowColor, ?? _defaultShadowColor,
shape: widget.shape, shape: widget.shape ?? appBarTheme.shape,
child: Semantics( child: Semantics(
explicitChildNodes: true, explicitChildNodes: true,
child: appBar, child: appBar,
......
...@@ -38,6 +38,7 @@ class AppBarTheme with Diagnosticable { ...@@ -38,6 +38,7 @@ class AppBarTheme with Diagnosticable {
this.foregroundColor, this.foregroundColor,
this.elevation, this.elevation,
this.shadowColor, this.shadowColor,
this.shape,
this.iconTheme, this.iconTheme,
this.actionsIconTheme, this.actionsIconTheme,
@Deprecated( @Deprecated(
...@@ -124,6 +125,10 @@ class AppBarTheme with Diagnosticable { ...@@ -124,6 +125,10 @@ class AppBarTheme with Diagnosticable {
/// descendant widgets. /// descendant widgets.
final Color? shadowColor; 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 /// Overrides the default value of [AppBar.iconTheme] in all
/// descendant [AppBar] widgets. /// descendant [AppBar] widgets.
/// ///
...@@ -229,6 +234,7 @@ class AppBarTheme with Diagnosticable { ...@@ -229,6 +234,7 @@ class AppBarTheme with Diagnosticable {
Color? foregroundColor, Color? foregroundColor,
double? elevation, double? elevation,
Color? shadowColor, Color? shadowColor,
ShapeBorder? shape,
IconThemeData? iconTheme, IconThemeData? iconTheme,
TextTheme? textTheme, TextTheme? textTheme,
bool? centerTitle, bool? centerTitle,
...@@ -249,6 +255,7 @@ class AppBarTheme with Diagnosticable { ...@@ -249,6 +255,7 @@ class AppBarTheme with Diagnosticable {
foregroundColor: foregroundColor ?? this.foregroundColor, foregroundColor: foregroundColor ?? this.foregroundColor,
elevation: elevation ?? this.elevation, elevation: elevation ?? this.elevation,
shadowColor: shadowColor ?? this.shadowColor, shadowColor: shadowColor ?? this.shadowColor,
shape: shape ?? this.shape,
iconTheme: iconTheme ?? this.iconTheme, iconTheme: iconTheme ?? this.iconTheme,
actionsIconTheme: actionsIconTheme ?? this.actionsIconTheme, actionsIconTheme: actionsIconTheme ?? this.actionsIconTheme,
textTheme: textTheme ?? this.textTheme, textTheme: textTheme ?? this.textTheme,
...@@ -280,6 +287,7 @@ class AppBarTheme with Diagnosticable { ...@@ -280,6 +287,7 @@ class AppBarTheme with Diagnosticable {
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t), elevation: lerpDouble(a?.elevation, b?.elevation, t),
shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, 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), iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t),
actionsIconTheme: IconThemeData.lerp(a?.actionsIconTheme, b?.actionsIconTheme, t), actionsIconTheme: IconThemeData.lerp(a?.actionsIconTheme, b?.actionsIconTheme, t),
textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t), textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t),
...@@ -301,6 +309,7 @@ class AppBarTheme with Diagnosticable { ...@@ -301,6 +309,7 @@ class AppBarTheme with Diagnosticable {
foregroundColor, foregroundColor,
elevation, elevation,
shadowColor, shadowColor,
shape,
iconTheme, iconTheme,
actionsIconTheme, actionsIconTheme,
textTheme, textTheme,
...@@ -326,6 +335,7 @@ class AppBarTheme with Diagnosticable { ...@@ -326,6 +335,7 @@ class AppBarTheme with Diagnosticable {
&& other.foregroundColor == foregroundColor && other.foregroundColor == foregroundColor
&& other.elevation == elevation && other.elevation == elevation
&& other.shadowColor == shadowColor && other.shadowColor == shadowColor
&& other.shape == shape
&& other.iconTheme == iconTheme && other.iconTheme == iconTheme
&& other.actionsIconTheme == actionsIconTheme && other.actionsIconTheme == actionsIconTheme
&& other.textTheme == textTheme && other.textTheme == textTheme
...@@ -346,6 +356,7 @@ class AppBarTheme with Diagnosticable { ...@@ -346,6 +356,7 @@ class AppBarTheme with Diagnosticable {
properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null));
properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));
properties.add(ColorProperty('shadowColor', shadowColor, 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>('iconTheme', iconTheme, defaultValue: null));
properties.add(DiagnosticsProperty<IconThemeData>('actionsIconTheme', actionsIconTheme, defaultValue: null)); properties.add(DiagnosticsProperty<IconThemeData>('actionsIconTheme', actionsIconTheme, defaultValue: null));
properties.add(DiagnosticsProperty<TextTheme>('textTheme', textTheme, defaultValue: null)); properties.add(DiagnosticsProperty<TextTheme>('textTheme', textTheme, defaultValue: null));
......
...@@ -37,6 +37,7 @@ void main() { ...@@ -37,6 +37,7 @@ void main() {
expect(widget.color, Colors.blue); expect(widget.color, Colors.blue);
expect(widget.elevation, 4.0); expect(widget.elevation, 4.0);
expect(widget.shadowColor, Colors.black); expect(widget.shadowColor, Colors.black);
expect(widget.shape, null);
expect(iconTheme.data, const IconThemeData(color: Colors.white)); expect(iconTheme.data, const IconThemeData(color: Colors.white));
expect(actionsIconTheme.data, const IconThemeData(color: Colors.white)); expect(actionsIconTheme.data, const IconThemeData(color: Colors.white));
expect(actionIconText.text.style!.color, Colors.white); expect(actionIconText.text.style!.color, Colors.white);
...@@ -72,6 +73,7 @@ void main() { ...@@ -72,6 +73,7 @@ void main() {
expect(widget.color, appBarTheme.backgroundColor); expect(widget.color, appBarTheme.backgroundColor);
expect(widget.elevation, appBarTheme.elevation); expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor); expect(widget.shadowColor, appBarTheme.shadowColor);
expect(widget.shape, const StadiumBorder());
expect(iconTheme.data, appBarTheme.iconTheme); expect(iconTheme.data, appBarTheme.iconTheme);
expect(actionsIconTheme.data, appBarTheme.actionsIconTheme); expect(actionsIconTheme.data, appBarTheme.actionsIconTheme);
expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color); expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color);
...@@ -131,6 +133,7 @@ void main() { ...@@ -131,6 +133,7 @@ void main() {
const Color color = Colors.orange; const Color color = Colors.orange;
const double elevation = 3.0; const double elevation = 3.0;
const Color shadowColor = Colors.red; const Color shadowColor = Colors.red;
const ShapeBorder shape = RoundedRectangleBorder();
const IconThemeData iconThemeData = IconThemeData(color: Colors.green); const IconThemeData iconThemeData = IconThemeData(color: Colors.green);
const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.lightBlue); const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.lightBlue);
const TextStyle toolbarTextStyle = TextStyle(color: Colors.pink); const TextStyle toolbarTextStyle = TextStyle(color: Colors.pink);
...@@ -138,7 +141,9 @@ void main() { ...@@ -138,7 +141,9 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData.from(colorScheme: const ColorScheme.light()), theme: ThemeData.from(colorScheme: const ColorScheme.light()).copyWith(
appBarTheme: _appBarTheme(),
),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: color, backgroundColor: color,
...@@ -146,6 +151,7 @@ void main() { ...@@ -146,6 +151,7 @@ void main() {
systemOverlayStyle: systemOverlayStyle, systemOverlayStyle: systemOverlayStyle,
elevation: elevation, elevation: elevation,
shadowColor: shadowColor, shadowColor: shadowColor,
shape: shape,
iconTheme: iconThemeData, iconTheme: iconThemeData,
actionsIconTheme: actionsIconThemeData, actionsIconTheme: actionsIconThemeData,
toolbarTextStyle: toolbarTextStyle, toolbarTextStyle: toolbarTextStyle,
...@@ -168,6 +174,7 @@ void main() { ...@@ -168,6 +174,7 @@ void main() {
expect(widget.color, color); expect(widget.color, color);
expect(widget.elevation, elevation); expect(widget.elevation, elevation);
expect(widget.shadowColor, shadowColor); expect(widget.shadowColor, shadowColor);
expect(widget.shape, shape);
expect(iconTheme.data, iconThemeData); expect(iconTheme.data, iconThemeData);
expect(actionsIconTheme.data, actionsIconThemeData); expect(actionsIconTheme.data, actionsIconThemeData);
expect(actionIconText.text.style!.color, actionsIconThemeData.color); expect(actionIconText.text.style!.color, actionsIconThemeData.color);
...@@ -525,6 +532,7 @@ AppBarTheme _appBarTheme() { ...@@ -525,6 +532,7 @@ AppBarTheme _appBarTheme() {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: elevation, elevation: elevation,
shadowColor: shadowColor, shadowColor: shadowColor,
shape: StadiumBorder(),
iconTheme: iconThemeData, iconTheme: iconThemeData,
toolbarHeight: 96, toolbarHeight: 96,
toolbarTextStyle: TextStyle(color: Colors.yellow), 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