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
Fix text color not resolving when CupertinoThemeData.brightness
is null
#115026
Fix text color not resolving when CupertinoThemeData.brightness
is null
#115026
Conversation
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. Changes reported for pull request #115026 at sha 7987b1a9c923b2ad62c2506b45e27c3eeef12092 |
Seems like this is related to the #114450. |
Hey @MitchellGoodwin, I've seen that you self-requested a review of this PR almost 1.5 months ago, and I just wanted to remind you about that in case you lost my PR in your review queue. |
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.
I posted a workaround and some details on the issue: #48438 (comment)
Ideally a solution would make Material and Cupertino behave identically here, where the brightness
is set automatically on the theme data, and they would both do so in the same way.
builder: _buildWidgetApp, | ||
), | ||
child: !widget.useInheritedMediaQuery | ||
? MediaQuery.fromWindow( |
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.
Isn't this sort of thing already being done in WidgetsApp?
flutter/packages/flutter/lib/src/widgets/app.dart
Lines 1754 to 1758 in 9a347fb
if (!widget.useInheritedMediaQuery || data == null) { | |
child = MediaQuery.fromWindow( | |
child: child, | |
); | |
} |
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.
It looks like MediaQuery.fromWindow
is planed for deprecation as well. #117480
Sorry I haven't responded to this sooner. I've been keeping an eye on this PR, but because it's dealing with code at the app level, I wanted to get a second opinion before reviewing. I think the reason why Material works correctly but Cupertino doesn't is that the check for the platform brightness happens in a builder passed to MaterialApp.
But in Cupertino it's happening in a static method in CupertinoTheme, so it's not automatically updating when the MediaQuery enters the tree. I'm guessing your solution is indirectly solving the issue by causing a rebuild in CupertinoApp that catches the change in the static method. Ideally the way the theme gets the default brightness would be passed in similar to Material in the builder. |
I've removed It works great, but I also found something else,
|
Thanks for making this update. Is there no way in either builder to get the platform brightness in order to get the right colors? Either through MediaQuery, or the workaround Justin mentioned? |
Well, it would be technically possible using the |
It can also be done by inserting a |
I think this makes the most sense to me, and we can fix the original issue, and move this one to a new one, if that is taking a while. |
Alright, it seems that #116924 and #118004 accidentally fixed the original bug with text color and it is now correctly resolved ( I've also noticed that |
My apologies @ivirtex, this somewhat slipped my attention. Can you rebase on the latest? It looks like I can't with the new option due to conflicts. Otherwise this looks gtg to me. |
3dd33d9
to
3b61334
Compare
This reverts commit 6994719a564c476dcb6d389e4547bff3ded08203.
5c57267
to
e449574
Compare
@MitchellGoodwin Conflicts are now resolved. Btw, would you mind taking a look at flutter/platform_tests#18? |
In the build method of the
CupertinoApp
,CupertinoTheme.of(context)
gets called before MediaQuery exists in the tree.By default, every value of the
CupertinoTheme.data
gets resolved according to theCupertinoThemeData.brightness
, but ifCupertinoThemeData.brightness
is null,MediaQuery.maybeOf(context)?.platformBrightness
is used.Due to the lack of
MediaQuery
in the tree,CupertinoTheme.data
gets its values resolved againstBrightness.light
.This causes text color to be constantly equal to black -
0xff000000
.flutter/packages/flutter/lib/src/cupertino/colors.dart
Lines 990 to 994 in 8b32ac7
Fixes #48438
Before / After
Pre-launch Checklist
///
).