Unverified Commit 7d9eaab0 authored by Eilidh Southren's avatar Eilidh Southren Committed by GitHub

Appbar iconTheme override fix (#118681)

* theme override fix

* add conditional centering
parent 11d21e06
......@@ -1023,7 +1023,6 @@ class _AppBarState extends State<AppBar> {
}
if (leading != null) {
if (theme.useMaterial3) {
if (leading is IconButton) {
final IconButtonThemeData effectiveIconButtonTheme;
// This comparison is to check if there is a custom [overallIconTheme]. If true, it means that no
......@@ -1048,13 +1047,10 @@ class _AppBarState extends State<AppBar> {
);
}
leading = Center(
child: IconButtonTheme(
leading = IconButtonTheme(
data: effectiveIconButtonTheme,
child: leading
)
child: leading is IconButton ? Center(child: leading) : leading,
);
}
// Based on the Material Design 3 specs, the leading IconButton should have
// a size of 48x48, and a highlight size of 40x40. Users can also put other
......
......@@ -3235,6 +3235,39 @@ void main() {
expect(actionIconButtonSize(), 30.0);
});
testWidgets('AppBar.iconTheme should override any IconButtonTheme present in the theme for widgets containing an iconButton - M3', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(
iconButtonTheme: IconButtonThemeData(
style: IconButton.styleFrom(
foregroundColor: Colors.red,
iconSize: 32.0,
),
),
useMaterial3: true,
);
const IconThemeData overallIconTheme = IconThemeData(color: Colors.yellow, size: 30.0);
await tester.pumpWidget(
MaterialApp(
theme: themeData,
home: Scaffold(
appBar: AppBar(
iconTheme: overallIconTheme,
leading: BackButton(onPressed: () {}),
title: const Text('title'),
),
),
),
);
Color? leadingIconButtonColor() => iconStyle(tester, Icons.arrow_back)?.color;
double? leadingIconButtonSize() => iconStyle(tester, Icons.arrow_back)?.fontSize;
expect(leadingIconButtonColor(), Colors.yellow);
expect(leadingIconButtonSize(), 30.0);
});
testWidgets('AppBar.actionsIconTheme should override any IconButtonTheme present in the theme - M3', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(
iconButtonTheme: IconButtonThemeData(
......@@ -3275,6 +3308,40 @@ void main() {
expect(actionIconButtonSize(), 30.0);
});
testWidgets('AppBar.actionsIconTheme should override any IconButtonTheme present in the theme for widgets containing an iconButton - M3', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(
iconButtonTheme: IconButtonThemeData(
style: IconButton.styleFrom(
foregroundColor: Colors.red,
iconSize: 32.0,
),
),
useMaterial3: true,
);
const IconThemeData actionsIconTheme = IconThemeData(color: Colors.yellow, size: 30.0);
await tester.pumpWidget(
MaterialApp(
theme: themeData,
home: Scaffold(
appBar: AppBar(
actionsIconTheme: actionsIconTheme,
title: const Text('title'),
actions: <Widget>[
BackButton(onPressed: () {}),
],
),
),
),
);
Color? actionIconButtonColor() => iconStyle(tester, Icons.arrow_back)?.color;
double? actionIconButtonSize() => iconStyle(tester, Icons.arrow_back)?.fontSize;
expect(actionIconButtonColor(), Colors.yellow);
expect(actionIconButtonSize(), 30.0);
});
testWidgets('The foregroundColor property of the AppBar overrides any IconButtonTheme present in the theme - M3', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(
iconButtonTheme: IconButtonThemeData(
......
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