-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Migrate IconButton to Material 3 - Part 1
#105176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate IconButton to Material 3 - Part 1
#105176
Conversation
a2ffa24 to
878d83d
Compare
guidezpl
left a comment
There was a problem hiding this 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// 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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8c40aa5 to
a258a49
Compare
a258a49 to
c1447d4
Compare
darrenaustin
left a comment
There was a problem hiding this 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.
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.

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
///).