-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[flutter_tools] add toggle b and service extension to change platform brightness
#59571
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
[flutter_tools] add toggle b and service extension to change platform brightness
#59571
Conversation
| /// window's metrics change. For example, see | ||
| /// [WidgetsBindingObserver.didChangeMetrics] or [Window.onMetricsChanged]. | ||
| MediaQueryData.fromWindow(ui.Window window) | ||
| MediaQueryData.fromWindow(ui.Window window, { ui.Brightness platformBrightness }) |
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.
@goderbauer thoughts on this API change? It seems likely to be non-breaking. I could instead create a mocked window ... but this seemed more straightforward
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.
Instead of adding the extra slightly awkward one-off API, could you just do the following in app.dart?
MediaQueryData data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
if (!kReleaseMode) {
data = data.copyWith(platformBrightness: debugBrightnessOverride);
}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.
Ahh, I missed the existing copyWith method - that seems more straightforward
b and service protocol to change platform brightnessb and service extension to change platform brightness
| return value.toStringAsFixed(1); | ||
| } | ||
|
|
||
| /// A brightness setting that overrides [ui.Brightness] when used through the [BindingBase]. |
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.
How do you use it "through the [BindingBase]"?
As implemented, it appears to be a debug setting in the widget layer, determining what brightness the MediaQuery of WidgetApp inserts into the tree, no?
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 guess it isn't really true - maybe "Used by MediaQuery to override the platform brightness?"
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.
Sounds better, we should probably move it to widgets/debug.dart then since its more a debug setting of that layer?
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 wasn't sure, the window is exposed through BindingBase which is where the Brightness comes from. If one was hypothetically depending only on foundation, it would not be usable if the brightness was in the widget layer
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.
Ah, that's fair. If we add some more documentation to this property here I am OK with leaving it where it as.
goderbauer
left a comment
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.
approach seems fine.
| } | ||
|
|
||
| /// A setting that can be used to override the platform [Brightness] exposed | ||
| /// from [BindingBase.window] |
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.
nitty nit: missing a .
| /// A setting that can be used to override the platform [Brightness] exposed | ||
| /// from [BindingBase.window] | ||
| /// | ||
| /// For an example of using [debugBrightnessOverride], see |
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.
Maybe just say "See also:" since that's our style. You could incorporate this half-sentence into the explanation after the [WidgetsApp], which below.
| name: 'exit', | ||
| callback: _exitApplication, | ||
| ); | ||
| registerServiceExtension( |
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 this just no longer a thing - or why remove it?
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.
its not a thing
| result = await binding.testExtension('brightnessOverride', <String, String>{}); | ||
| final String brightnessValue = result['value'] as String; | ||
|
|
||
| expect(brightnessValue, 'Brightness.light'); |
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.
Can dark be tested?
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 can't actually change the value in this test or I'll trigger reassemble and break the test framework. I will update the integration test
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.
the integration test now confirms both brightness settings and that a bogus value does not change anything
| CommandHelpOption _b; | ||
| CommandHelpOption get b => _b ??= _makeOption( | ||
| 'b', | ||
| 'Toggle the platform brightness setting.', |
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 didn't know what "brightness" meant, maybe 'Toggle the platform brightness (dark and light mode).'?
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 idea, fixed
jmagman
left a comment
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.
Impressed how quickly you did this based on survey feedback!
| isolateId: isolate.id, | ||
| args: <String, String>{ | ||
| 'value': 'dark', | ||
| } |
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.
Can you add a comment that this is purposely bogus? It looks like a bug in the test.
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.
Done
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.
Done
|
Thanks! its not my first rodeo 🐮 🥍 😄 |
I said "impressed" not "surprised". 😉 |
goderbauer
left a comment
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
| await reassembleApplication(); | ||
| } | ||
| return <String, dynamic>{ | ||
| 'value': (debugBrightnessOverride ?? window.platformBrightness) |
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.
nitty nit: just leave the .toString() on this line? Looks so lonely on the next.
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.
Gave it some friends
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [WidgetsApp], which uses the [debugBrightnessOverride] setting to construct a [MediaQueryData]. |
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.
maybe add that it only uses it in debug mode.
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.
Done
…rm brightness (flutter#59571) A frequent request from the last Flutter developer survey was for an easier method of testing light/dark mode changes. Currently, a user needs to manually change the theme settings or adjust phone settings to see the difference. Instead we should add a toggle from the CLI, and eventually devtools/Intellij/Vscode that allows developers to override the current setting. Fixes flutter#59495 Adds flutter.ext.brightnessOverride service protocol which either queries the current platform brightness, or overrides it to a new value. This accepts either Brightness.light or Brightness.dark as a value. Adds a CLI toggle b which allows the setting to be toggled manually. Requires an update to the MediaQuery, to conditionally use a debug override when not in release mode
…rm brightness (flutter#59571) A frequent request from the last Flutter developer survey was for an easier method of testing light/dark mode changes. Currently, a user needs to manually change the theme settings or adjust phone settings to see the difference. Instead we should add a toggle from the CLI, and eventually devtools/Intellij/Vscode that allows developers to override the current setting. Fixes flutter#59495 Adds flutter.ext.brightnessOverride service protocol which either queries the current platform brightness, or overrides it to a new value. This accepts either Brightness.light or Brightness.dark as a value. Adds a CLI toggle b which allows the setting to be toggled manually. Requires an update to the MediaQuery, to conditionally use a debug override when not in release mode
Description
A frequent request from the last Flutter developer survey was for an easier method of testing light/dark mode changes. Currently, a user needs to manually change the theme settings or adjust phone settings to see the difference. Instead we should add a toggle from the CLI, and eventually devtools/Intellij/Vscode that allows developers to override the current setting.
Fixes #59495
Adds
flutter.ext.brightnessOverrideservice protocol which either queries the current platform brightness, or overrides it to a new value. This accepts eitherBrightness.lightorBrightness.darkas a value.Adds a CLI toggle
bwhich allows the setting to be toggled manually.Requires an update to the MediaQuery, to conditionally use a debug override when not in release mode