-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Added MaterialApp.themeMode to control which theme is used. #35499
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
Conversation
how the light or dark theme is selected.
| expect(appliedTheme.brightness, Brightness.dark); | ||
| }); | ||
|
|
||
| testWidgets('MaterialApp uses regular theme when themeMode is system & platformBrightness is light', (WidgetTester tester) async { |
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.
Is it possible that use of symbols like "&" in test names could cause complications for devs that try to execute specific tests via command line? Seems like there could be cases where this might require some kind of encoding, e.g., URL encoding, which would be an unnecessary burden...
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.
Good point, I will fix this.
|
Generally LGTM. One case where things end up conflicting is if I set the |
I get the issue, but don't see a way to address it other than through documentation. One possibility might be to have a default value for I view the |
Removed '&' from test names to avoid shell quoting issues.
|
Yeah, I think this is probably the best we can do WRT to the platform vs provided themes issue. So LGTM. |
…35499) Added support for a themeMode property to the MaterialApp to control how the light or dark theme is selected.
Description
In order to make is easier for applications to provide support for switching between light and dark themes, or just letting the system do it for them, this PR adds a
ThemeMode themeModeproperty to theMaterialApp.ThemeModeis a new enum that has three values:system: use eitherthemeordarkThemebased on the platform's "dark mode" settings.light: always usetheme, regardless of the system setting.dark: always usedarkTheme, regardless of the system setting.It defaults to
system, which maintains the current behavior.Without this, writing an app that wanted to override the system setting would require them to use only the
themeproperty even if they had to set it to their 'dark' theme. This way they can just setthemeanddarkThemeappropriately and just switch the mode as needed.Tests
I added several tests to verify that the various combinations of
themeModeand platform brightness were handled correctly.Checklist
///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?