Added MaterialApp.themeMode to control which theme is used.#35499
Added MaterialApp.themeMode to control which theme is used.#35499darrenaustin merged 2 commits intoflutter:masterfrom darrenaustin:theme_mode
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.
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.
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?