-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Have Material widgets in a Cupertino App partially use Cupertino theme #139253
Have Material widgets in a Cupertino App partially use Cupertino theme #139253
Conversation
24dee46
to
6798972
Compare
CC @QuncCccccc @HansMuller this is a fairly simple fix, but feels like a bandaid on a larger issue. Theoretically this should make it so that if But this does put a bandaid on a larger issue. I was surprised to find that a Material theme will wrap itself with a Cupertino theme. So Material widgets in a Cupertino app with no Material theme ancestor will create their own Cupertino theme, regardless of there already being one, which feels gross. I did try and wrap a basic Material theme around the Cupertino app widget to copy the solution from the Material side, but that created a dependency loop. Which was almost a relief because that was ugly too. I think it is important to fix this issue with something simple like this, but ideally the two themes would be aware of each other, if not unified in some way. |
I think this fix is smart! But not sure if this change will cause any confusion because we just made material 3 be default and then in this PR, we change the fallback to false? |
My intention was to have Cupertino apps default to having the material 3 flag be false. And as far as I can tell, that fallback is only used when there is no theme in the tree. So it should not be used when either a |
Ah some unit tests might just build a widget without using But other than this, I also don't see any other use cases:) |
I spoke to @MitchellGoodwin and he said this is still on his radar. |
Converting this to a draft, as if the |
c33b327
to
5ada14a
Compare
@HansMuller this it the draft for having the themes get along. I'll add documentation recommending that developers add a Material theme to their Cupertino apps. |
5ada14a
to
8fed6c0
Compare
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.
This solution makes sense to me! LGTM:) The new classes might need some more documentation.
8fed6c0
to
47bd703
Compare
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:)
/// [ThemeData], so if further customization is needed, it is best to manually | ||
/// add a Material [Theme] above the [CupertinoApp]. | ||
class CupertinoBasedMaterialThemeData { | ||
|
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.
auto label is removed for flutter/flutter/139253, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
340412a
to
a327d6e
Compare
flutter#139253) Fixes flutter#138621 Fixes and issue where if a Material widget is used in a Cupertino App, then some parts of it's default Material 3 theming would show up as purplish. This could be fixed by wrapping your app with a Material theme, but that's a little awkward. Material and Cupertino themes interact with each other a little oddly. If a theme of either is searched for but does not exist, then a default one is generated. So if a Material widget is in a Cupertino app that does not already have a Material theme, then a fallback Material theme will be created. This PR makes it so that, in this case when that Material theme is created, it's default colors will be based on the Cupertino theme. Another oddity is that a Material theme always wraps itself with a Cupertino theme that's values are based on the Material theme. So before this change, a Material widget would theoretically add a new Material based Cupertino theme to the tree. So I added logic that would have the Material theme check to see if a Cupertino theme exists, before it overwrites it. Before: ![image](https://github.com/flutter/flutter/assets/58190796/95874076-e943-48fa-ba9d-1d7b0f5a2f38) After: <img width="386" alt="Screenshot 2023-11-29 at 10 37 09�AM" src="https://github.com/flutter/flutter/assets/58190796/959ccfd9-3439-438e-ad36-20597334837a"> Update: I changed it to not rely on the Material 3 flag. Instead, if a Material theme is searched for and there is already a Cupertino theme in the tree, then it will use that Cupertino theme instead of generating a new. Also, if a Material theme is searched for, and it does not find one already in the tree, but does find a Cupertino theme, then it will generate one with a color palette based off of that Cupertino theme's colors. After with this change: <img width="390" alt="Screenshot 2024-05-09 at 10 16 22�AM" src="https://github.com/flutter/flutter/assets/58190796/79765d04-a7a3-4eb5-9477-11668ed138e5"> We should still probably suggest for developers to include a Material theme in their Cupertino app if they wish to use widgets from both packages.
Fixes #138621
Fixes and issue where if a Material widget is used in a Cupertino App, then some parts of it's default Material 3 theming would show up as purplish. This could be fixed by wrapping your app with a Material theme, but that's a little awkward.
Material and Cupertino themes interact with each other a little oddly. If a theme of either is searched for but does not exist, then a default one is generated. So if a Material widget is in a Cupertino app that does not already have a Material theme, then a fallback Material theme will be created. This PR makes it so that, in this case when that Material theme is created, it's default colors will be based on the Cupertino theme.
Another oddity is that a Material theme always wraps itself with a Cupertino theme that's values are based on the Material theme. So before this change, a Material widget would theoretically add a new Material based Cupertino theme to the tree. So I added logic that would have the Material theme check to see if a Cupertino theme exists, before it overwrites it.
Before:
![image](https://private-user-images.githubusercontent.com/58190796/286707263-95874076-e943-48fa-ba9d-1d7b0f5a2f38.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MDg3MzQsIm5iZiI6MTcyMTQwODQzNCwicGF0aCI6Ii81ODE5MDc5Ni8yODY3MDcyNjMtOTU4NzQwNzYtZTk0My00OGZhLWJhOWQtMWQ3YjBmNWEyZjM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE5VDE3MDAzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIxNGNjNGFjNTZlZDQ0MWI4NGQ0Y2ZmZThmY2RjY2Q2MzlhMjYwNzdmMWE5OGQ4OTZkY2M5MGRiZjI2ZDBlMDUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.yDEAu-ryVPgWIhIndKrJ2aSG_H8Jbg-aBqfznBujLpM)
After:
![Screenshot 2023-11-29 at 10 37 09 AM](https://private-user-images.githubusercontent.com/58190796/286707337-959ccfd9-3439-438e-ad36-20597334837a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MDg3MzQsIm5iZiI6MTcyMTQwODQzNCwicGF0aCI6Ii81ODE5MDc5Ni8yODY3MDczMzctOTU5Y2NmZDktMzQzOS00MzhlLWFkMzYtMjA1OTczMzQ4MzdhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE5VDE3MDAzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlZWEwYzhkN2I5MGNiZWQzNGZiMjUzYTM4YTY1YTYxNzY5OTk5MWExZjc3NjRmMzI2ZjE2NDA4NThhNTczNTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FzI0CH91xo2tuuMayPAUhTKxwNr6ph87AYbmQ9xbYYI)
Update:
I changed it to not rely on the Material 3 flag. Instead, if a Material theme is searched for and there is already a Cupertino theme in the tree, then it will use that Cupertino theme instead of generating a new. Also, if a Material theme is searched for, and it does not find one already in the tree, but does find a Cupertino theme, then it will generate one with a color palette based off of that Cupertino theme's colors.
After with this change:
![Screenshot 2024-05-09 at 10 16 22 AM](https://private-user-images.githubusercontent.com/58190796/329330304-79765d04-a7a3-4eb5-9477-11668ed138e5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MDg3MzQsIm5iZiI6MTcyMTQwODQzNCwicGF0aCI6Ii81ODE5MDc5Ni8zMjkzMzAzMDQtNzk3NjVkMDQtYTdhMy00ZWI1LTk0NzctMTE2NjhlZDEzOGU1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE5VDE3MDAzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ3M2I0ODBlNDMxMjA1M2NmNjM1NzFhYTU3NzE4NTFkZTM4MTJjNWE3NjUzYjQxODY2NzdiMjgyOGY4MTEyM2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.hpS0gKHYaMdE0MdDLKpdUl488eRolw0uiQAYOmZPTJE)
We should still probably suggest for developers to include a Material theme in their Cupertino app if they wish to use widgets from both packages.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.