Skip to content

Conversation

@matthew-carroll
Copy link
Contributor

Starting in Android Pie, when battery saver is on, or when the developer option for "Night Mode" is enabled, Android apps should show a dark styled UI. This PR introduces this behavior to Flutter.

This is the framework half of the change. The engine PR here is here:
flutter/engine#7488

On the framework side, this PR integrates the new platformBrightness property into MediaQuery and then binds WidgetsApp to that property so that the widget hierarchy rebuilds on change to brightness.

Supporting Flutter changes for brightness required adding uiMode to the Android manifest under overridden configuration changes for FlutterActivity.

@zoechi zoechi added platform-android Android applications specifically framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 16, 2019
Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

LG. Please add tests

@xster
Copy link
Member

xster commented Jan 30, 2019

specifically re tests:

  • check that the darkTheme is used when a mock window or the platform sends Brightness.dark
  • check that the theme and darkTheme toggles automatically via a descendent Material widget when the platform toggles
  • check that the theme is indeed used when darkTheme is undefined.

In general, I think it's a good idea to run flutter test --coverage and making sure all the new lines are covered until we have an infra to display it in GitHub. You can see the lcov with a vscode extension or something (or you can just read the output file).

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

This looks good, just some small requests.

@matthew-carroll
Copy link
Contributor Author

@HansMuller @goderbauer @xster - I just pushed a number of updates based on comments. Can you all do another pass?

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM if it looks good to @xster and @HansMuller as well.

@goderbauer
Copy link
Member

Looks like cirrus is not too happy, though.

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for adding tests.

…a SemanticsHandle and it was unclear how to do that.
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM with a few suggestions

@matthew-carroll matthew-carroll merged commit a13fdbc into flutter:master Feb 7, 2019
kangwang1988 pushed a commit to XianyuTech/flutter that referenced this pull request Feb 12, 2019
@creativecreatorormaybenot
Copy link
Contributor

creativecreatorormaybenot commented Feb 21, 2019

@matthew-carroll How can I change the platformBrightness value and also affect the MaterialApp theme? I implemented adding a MediaQuery with my custom value for platformBrightness similar to how it was done here. I even tried setting state of the widget containing the MaterialApp via WidgetBindingsObserver's didChangePlatformBrightness. The MediaQuery has the correct value down the tree, but the theme does not change accordingly. However, when I toggle the device to dark mode it works fine. What part am I missing?

The MaterialApp has both theme and darkTheme populated.

@matthew-carroll
Copy link
Contributor Author

@creativecreatorormaybenot can you please file this question as an issue instead of a PR comment? Also, can you please include as much of your actual code as possible? I need to see exactly what you're doing to be able to comment.

@mrk-han mrk-han mentioned this pull request May 15, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants