Skip to content

App bar leading theme overrides should apply to all widgets with IconButton children #118677

@esouthren

Description

@esouthren

Relates to #118216.

This fix allowed users to supply values to appBarTheme.iconTheme and appBarTheme.actionsIconTheme, which would override any theme.iconButtonTheme also set in the theme.

However, this fix only applies to widgets that are directly IconButtons. If, for example, our app bar was defined with these theme overrides:

return Theme(
      data: theme.copyWith(
        iconButtonTheme: IconButtonThemeData(
          style: IconButton.styleFrom(
            foregroundColor: Colors.yellow,
          ),
        ),
        appBarTheme: theme.appBarTheme.copyWith(
          actionsIconTheme: actionTheme!.copyWith(color: Colors.blue),
          iconTheme: leadingTheme!.copyWith(color: Colors.blue),
        ),
      ),
      child: Scaffold(
        appBar: AppBar(
          actions: [
            IconButton(
              icon: Icon(Icons.favorite),
              onPressed: () {},
            ),
            BackButton(), // this takes actionsIconTheme color value as expected
          ],
          leading: BackButton(), // this takes iconButtonTheme color value, not iconTheme
          title: Text('title'),
        ),
        body: body,

We get this result:
4cpMFh5rmnXsgsN

This is due to app_bar.dart checking for an exact widget type of IconButton before it applies the local theme override. So, it doesn't get applied to widgets like BackButton, or any other custom widget which contains an icon button.

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions