This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] change status bar color based on SystemUiOverlayStyle #40599
Merged
auto-submit
merged 12 commits into
flutter:main
from
maRci002:web-change-status-bar-color
Apr 20, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d9021f
web change status bar color
maRci002 6dbd787
add arguments for SystemChrome.setSystemUIOverlayStyle message
maRci002 ee73141
Merge branch 'main' into web-change-status-bar-color
kevmoo fecfa90
Merge branch 'flutter:main' into web-change-status-bar-color
maRci002 77176c8
Update based on conversation
maRci002 f29c65a
fix typo
maRci002 aab6301
Place platform_dispatcher_test in their correct locations.
ditman c06612a
Merge branch 'main' into web-change-status-bar-color
ditman 14cca60
Show warning message in debug mode
maRci002 958d26c
Merge branch 'main' into web-change-status-bar-color
maRci002 4ddbb84
Restore old functionality so this is backwards compatible.
ditman b4a6c52
Merge branch 'main' into web-change-status-bar-color
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
lib/web_ui/test/engine/platform_dispatcher/application_switcher_description_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
import 'package:ui/ui.dart' as ui; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
Future<void> testMain() async { | ||
ensureFlutterViewEmbedderInitialized(); | ||
|
||
String? getCssThemeColor() { | ||
final DomHTMLMetaElement? theme = | ||
domDocument.querySelector('#flutterweb-theme') as DomHTMLMetaElement?; | ||
return theme?.content; | ||
} | ||
|
||
const MethodCodec codec = JSONMethodCodec(); | ||
|
||
group('Title and Primary Color/Theme meta', () { | ||
test('is set on the document by platform message', () { | ||
// Run the unit test without emulating Flutter tester environment. | ||
ui.debugEmulateFlutterTesterEnvironment = false; | ||
|
||
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159 | ||
domDocument.title = ''; | ||
expect(domDocument.title, ''); | ||
expect(getCssThemeColor(), isNull); | ||
|
||
ui.window.sendPlatformMessage( | ||
'flutter/platform', | ||
codec.encodeMethodCall(const MethodCall( | ||
'SystemChrome.setApplicationSwitcherDescription', | ||
<String, dynamic>{ | ||
'label': 'Title Test', | ||
'primaryColor': 0xFF00FF00, | ||
}, | ||
)), | ||
null, | ||
); | ||
|
||
const ui.Color expectedPrimaryColor = ui.Color(0xFF00FF00); | ||
|
||
expect(domDocument.title, 'Title Test'); | ||
expect(getCssThemeColor(), colorToCssString(expectedPrimaryColor)); | ||
|
||
ui.window.sendPlatformMessage( | ||
'flutter/platform', | ||
codec.encodeMethodCall(const MethodCall( | ||
'SystemChrome.setApplicationSwitcherDescription', | ||
<String, dynamic>{ | ||
'label': 'Different title', | ||
'primaryColor': 0xFFFABADA, | ||
}, | ||
)), | ||
null, | ||
); | ||
|
||
const ui.Color expectedNewPrimaryColor = ui.Color(0xFFFABADA); | ||
|
||
expect(domDocument.title, 'Different title'); | ||
expect(getCssThemeColor(), colorToCssString(expectedNewPrimaryColor)); | ||
}); | ||
|
||
test('supports null title and primaryColor', () { | ||
// Run the unit test without emulating Flutter tester environment. | ||
ui.debugEmulateFlutterTesterEnvironment = false; | ||
|
||
const ui.Color expectedNullColor = ui.Color(0xFF000000); | ||
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159 | ||
domDocument.title = 'Something Else'; | ||
expect(domDocument.title, 'Something Else'); | ||
|
||
ui.window.sendPlatformMessage( | ||
'flutter/platform', | ||
codec.encodeMethodCall(const MethodCall( | ||
'SystemChrome.setApplicationSwitcherDescription', | ||
<String, dynamic>{ | ||
'label': null, | ||
'primaryColor': null, | ||
}, | ||
)), | ||
null, | ||
); | ||
|
||
expect(domDocument.title, ''); | ||
expect(getCssThemeColor(), colorToCssString(expectedNullColor)); | ||
|
||
domDocument.title = 'Something Else'; | ||
expect(domDocument.title, 'Something Else'); | ||
|
||
ui.window.sendPlatformMessage( | ||
'flutter/platform', | ||
codec.encodeMethodCall(const MethodCall( | ||
'SystemChrome.setApplicationSwitcherDescription', | ||
<String, dynamic>{}, | ||
)), | ||
null, | ||
); | ||
|
||
expect(domDocument.title, ''); | ||
expect(getCssThemeColor(), colorToCssString(expectedNullColor)); | ||
}); | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/web_ui/test/engine/platform_dispatcher/system_ui_overlay_style_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
import 'package:ui/ui.dart' as ui; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
void testMain() { | ||
ensureFlutterViewEmbedderInitialized(); | ||
|
||
const MethodCodec codec = JSONMethodCodec(); | ||
|
||
void sendSetSystemUIOverlayStyle({ui.Color? statusBarColor}) { | ||
ui.window.sendPlatformMessage( | ||
'flutter/platform', | ||
codec.encodeMethodCall(MethodCall( | ||
'SystemChrome.setSystemUIOverlayStyle', | ||
<String, dynamic>{ | ||
'statusBarColor': statusBarColor?.value, | ||
}, | ||
)), | ||
null, | ||
); | ||
} | ||
|
||
String? getCssThemeColor() { | ||
final DomHTMLMetaElement? theme = | ||
domDocument.querySelector('#flutterweb-theme') as DomHTMLMetaElement?; | ||
return theme?.content; | ||
} | ||
|
||
group('SystemUIOverlayStyle', () { | ||
test('theme color is set / removed by platform message', () { | ||
// Run the unit test without emulating Flutter tester environment. | ||
ui.debugEmulateFlutterTesterEnvironment = false; | ||
|
||
expect(getCssThemeColor(), null); | ||
|
||
const ui.Color statusBarColor = ui.Color(0xFFF44336); | ||
sendSetSystemUIOverlayStyle(statusBarColor: statusBarColor); | ||
expect(getCssThemeColor(), colorToCssString(statusBarColor)); | ||
|
||
sendSetSystemUIOverlayStyle(); | ||
expect(getCssThemeColor(), null); | ||
}); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.