Migrate IconButton to Material 3 - Part 1#105176
Conversation
a2ffa24 to
878d83d
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:)
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
| /// by configuring the [IconButton] widget's properties. | |
| /// by providing [style]. |
If defaults are added, mention them here "as a starting point ...standard.copyWith(...)"
There was a problem hiding this comment.
My natural question as a developer is, what do I use to specify splash radius? Please add a little more information to these comments.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Agreed, in a follow on API that addresses the variants, we can look at breaking these out.
|
In documentation and API, consider supporting 2 types (4 variants total):
|
IconButton to Material 3 - Part 1
ca82cb2 to
ed78ae3
Compare
darrenaustin
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Agreed, in a follow on API that addresses the variants, we can look at breaking these out.
8c40aa5 to
a258a49
Compare
a258a49 to
c1447d4
Compare
darrenaustin
left a comment
There was a problem hiding this comment.
LGTM. Nice work.
Looks like there are still some analyzer failures that will need to be fixed before we can merge this.
There was a problem hiding this comment.
Do the button style buttons not require a Material widget as well?
There was a problem hiding this comment.
No:) The ButtonStyleButton has its Material widget inside, but the original IconButton doesn't have one.
b774d7a to
7f6e9d5
Compare
* 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]>
| final Size? minSize = constraints == null | ||
| ? null | ||
| : Size(constraints!.minWidth, constraints!.minHeight); | ||
| final Size? maxSize = constraints == null | ||
| ? null | ||
| : Size(constraints!.maxWidth, constraints!.maxHeight); |
There was a problem hiding this comment.
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.

resolves #103528
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:
This also adds a new
styleparameter to theIconButtonclass that allows apps to configure button'sButtonStyle. 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
///).