Skip to content

Conversation

@QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Jun 1, 2022

resolves #103528

Screen Shot 2022-06-01 at 3 09 47 PM

Screen Shot 2022-06-02 at 11 41 18 AM

As part of the migration to Material Design 3, the icon button needs to be updated to the latest design spec:

https://m3.material.io/components/icon-buttons/overview

In order to use the IconButton with the new Material 3 defaults, turn on the useMaterial3 flag in the ThemeData:

  return MaterialApp(
    theme: ThemeData(useMaterial3: true),
    // ...
  );

This also adds a new style parameter to the IconButton class that allows apps to configure button's ButtonStyle. Similar to the common buttons, IconButton in M3 is a subclass of ButtonStyleButton now.

The second PR will come to enable IconButtons to be toggled.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jun 1, 2022
@QuncCccccc QuncCccccc force-pushed the migrate_icon_button_style branch 3 times, most recently from a2ffa24 to 878d83d Compare June 2, 2022 05:28
@QuncCccccc QuncCccccc marked this pull request as ready for review June 2, 2022 05:30
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 that there are tests

Comment on lines +69 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use tokens for these. We should also provide the three default styles, so that devs don't have to copy paste and have a nice starting point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we have a similar problem with the variants in the common buttons as well. I didn't realize the variants would need that much configuration.

I really wish we had a simpler way of providing these variants without a lot of extra API baggage to go with them (i.e. either full button subclasses for each variant, or named constructors that have to duplicate all the constructor parameters and use an enum or something to indicate which set of defaults to use in the build method).

That said, I would go with this example for this PR and we can look at cleaning up the variant support in a future PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current Flutter master channel (9160359), IconButton.styleFrom gives me stadium shapes by default. This is consistent with icon_button.dart#L614, below.

I believe the spec for md.sys.shape.corner.full indicates they should use shape: const CircleBorder() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the icon button is migrated to be a subclass of ButtonStyleButton now and has a compact VisualDensity on desktop platform, so the buttons don't look like circular. If the app is ran on iOS/Android, the buttons will show a standard VisualDensity and have a circular shape.

If this is the problem that you are facing, adding visualDensity: VisualDensity.standard to IconButton or IconButton.styleFrom() will solve the problem on desktop platform:)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuncCccccc Interesting, thanks! I didn't appreciate that property. The spec does have a "high-emphasis filled button for End call" in an example, but it's a bit subtle.

For reference, I see the issue in Flutter web.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I assumed you are using a desktop platform. Both desktop and web have a compact visual density as a default value because they have a larger screen, compared to phone devices. So on web, just adding same thing as desktop (visualDensity: VisualDensity.standard) will provide a circular icon button:)

Please let me know if there's any other problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// by configuring the [IconButton] widget's properties.
/// by providing [style].

If defaults are added, mention them here "as a starting point ...standard.copyWith(...)"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My natural question as a developer is, what do I use to specify splash radius? Please add a little more information to these comments.

Copy link
Member

@guidezpl guidezpl Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these have tokens per variant, it may be worth generating 3 separate _TokenDefaultsM3 for each of the styles, instead of my previous recommendation, e.g. md.comp.outlined-icon-button.unselected.outline.color and md.comp.outlined-icon-button.unselected.outline.width.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, in a follow on API that addresses the variants, we can look at breaking these out.

@guidezpl
Copy link
Member

guidezpl commented Jun 2, 2022

In documentation and API, consider supporting 2 types (4 variants total):

  • Standard icon button
  • Contained icon button (including filled, filled tonal, and outlined styles)

@QuncCccccc QuncCccccc changed the title Migrate common buttons to Material 3 - Part 1 Migrate IconButton to Material 3 - Part 1 Jun 2, 2022
@QuncCccccc QuncCccccc force-pushed the migrate_icon_button_style branch from ca82cb2 to ed78ae3 Compare June 2, 2022 22:44
Copy link
Contributor

@darrenaustin darrenaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I have reviewed the main code and it looks good. Just a couple of comments and suggestions below.

For the variants, I suggest just going with the examples you have and we can update this in a future PR after coming up with a better way to handle these.

I haven't had a chance to review the tests yet (thanks for including them 😄). I will look at them with fresh eyes tomorrow.

Until then in addition to the suggestions below, it looks like there are several analyzer warnings that will need to be fixed. Thx.

Comment on lines +69 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we have a similar problem with the variants in the common buttons as well. I didn't realize the variants would need that much configuration.

I really wish we had a simpler way of providing these variants without a lot of extra API baggage to go with them (i.e. either full button subclasses for each variant, or named constructors that have to duplicate all the constructor parameters and use an enum or something to indicate which set of defaults to use in the build method).

That said, I would go with this example for this PR and we can look at cleaning up the variant support in a future PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, in a follow on API that addresses the variants, we can look at breaking these out.

@QuncCccccc QuncCccccc force-pushed the migrate_icon_button_style branch from 8c40aa5 to a258a49 Compare June 3, 2022 19:43
@QuncCccccc QuncCccccc force-pushed the migrate_icon_button_style branch from a258a49 to c1447d4 Compare June 6, 2022 17:52
Copy link
Contributor

@darrenaustin darrenaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work.

Looks like there are still some analyzer failures that will need to be fixed before we can merge this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the button style buttons not require a Material widget as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No:) The ButtonStyleButton has its Material widget inside, but the original IconButton doesn't have one.

@QuncCccccc QuncCccccc force-pushed the migrate_icon_button_style branch from b774d7a to 7f6e9d5 Compare June 7, 2022 17:20
@QuncCccccc QuncCccccc merged commit 66a84d1 into flutter:master Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 8, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
* Added standard IconButton for M3 with new ButtonStyle field

* Added IconButton examples for standard, filled, filled_tonal, and outlined types

Co-authored-by: Qun Cheng <[email protected]>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
Comment on lines +461 to +466
final Size? minSize = constraints == null
? null
: Size(constraints!.minWidth, constraints!.minHeight);
final Size? maxSize = constraints == null
? null
: Size(constraints!.maxWidth, constraints!.maxHeight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @QuncCccccc , quick question
Why are you calculating new size, shouldn't we be using adjustedConstraints instead ?
This results in non-square icon buttons which depends on the icon itself causing weird behavior.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update IconButton to support Material 3

5 participants