-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Extend SystemUiOverlayStyle with additonal values for each platform #17171
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
Changes from all commits
e823b9a
82293a8
a6ed815
bb6510a
989f1c4
518ff04
897b538
e7c45ec
c2f6bd4
761b7e2
8bbaaaf
06a44de
5aa13cf
59fbb8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
|
|
@@ -77,17 +78,142 @@ enum SystemUiOverlay { | |
| bottom, | ||
| } | ||
|
|
||
| /// Describes the contrast needs of a color. | ||
| enum Brightness { | ||
| /// The color is dark and will require a light text color to achieve readable | ||
| /// contrast. | ||
| /// | ||
| /// For example, the color might be dark grey, requiring white text. | ||
| dark, | ||
|
|
||
| /// The color is light and will require a dark text color to achieve readable | ||
| /// contrast. | ||
| /// | ||
| /// For example, the color might be bright white, requiring black text. | ||
| light, | ||
| } | ||
|
|
||
| /// Specifies a preference for the style of the system overlays. | ||
| /// | ||
| /// Used by [SystemChrome.setSystemUIOverlayStyle]. | ||
| enum SystemUiOverlayStyle { | ||
| class SystemUiOverlayStyle { | ||
| /// System overlays should be drawn with a light color. Intended for | ||
| /// applications with a dark background. | ||
| light, | ||
| static const SystemUiOverlayStyle light = const SystemUiOverlayStyle( | ||
| systemNavigationBarColor: const Color(0xFFFFFFFF), | ||
| systemNavigationBarDividerColor: null, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want a shade of gray here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I haven't gotten a chance to play with the P preview I don't really know what the behavior is. null makes sure the API isn't invoked yet.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I imagine that we'll have to render this divider on the framework side anyway. |
||
| statusBarColor: null, | ||
| systemNavigationBarIconBrightness: Brightness.dark, | ||
| statusBarIconBrightness: Brightness.dark, | ||
| statusBarBrightness: Brightness.dark, | ||
| ); | ||
|
|
||
| /// System overlays should be drawn with a dark color. Intended for | ||
| /// applications with a light background. | ||
| dark, | ||
| static const SystemUiOverlayStyle dark = const SystemUiOverlayStyle( | ||
| systemNavigationBarColor: const Color(0xFF000000), | ||
| systemNavigationBarDividerColor: null, | ||
| statusBarColor: null, | ||
| systemNavigationBarIconBrightness: Brightness.light, | ||
| statusBarIconBrightness: Brightness.light, | ||
| statusBarBrightness: Brightness.light, | ||
| ); | ||
|
|
||
| /// Creates a new [SystemUiOverlayStyle]. | ||
| const SystemUiOverlayStyle({ | ||
| this.systemNavigationBarColor, | ||
| this.systemNavigationBarDividerColor, | ||
| this.systemNavigationBarIconBrightness, | ||
| this.statusBarColor, | ||
| this.statusBarBrightness, | ||
| this.statusBarIconBrightness, | ||
| }); | ||
|
|
||
| /// The color of the system bottom navigation bar. | ||
| /// | ||
| /// Only honored in Android versions O and greater. | ||
| final Color systemNavigationBarColor; | ||
|
|
||
| /// The color of the divider between the system's bottom navigation bar and the app's content. | ||
| /// | ||
| /// Only honored in Android versions P and greater. | ||
| final Color systemNavigationBarDividerColor; | ||
|
|
||
| /// The brightness of the system navigation bar icons. | ||
| /// | ||
| /// Only honored in Android versions O and greater. | ||
| final Brightness systemNavigationBarIconBrightness; | ||
|
|
||
| /// The color of top status bar. | ||
| /// | ||
| /// Only honored in Android version M and greater. | ||
| final Color statusBarColor; | ||
|
|
||
| /// The brightness of top status bar. | ||
| /// | ||
| /// Only honored in iOS . | ||
| final Brightness statusBarBrightness; | ||
|
|
||
| /// The brightness of the top status bar icons. | ||
| /// | ||
| /// Only honored in Android version M and greater. | ||
| final Brightness statusBarIconBrightness; | ||
|
|
||
| /// Convert this event to a map for serialization. | ||
| Map<String, dynamic> _toMap() { | ||
| return <String, dynamic>{ | ||
| 'systemNavigationBarColor': systemNavigationBarColor?.value, | ||
| 'systemNavigationBarDividerColor': systemNavigationBarDividerColor?.value, | ||
| 'statusBarColor': statusBarColor?.value, | ||
| 'statusBarBrightness': statusBarBrightness?.toString(), | ||
| 'statusBarIconBrightness': statusBarIconBrightness?.toString(), | ||
| 'systemNavigationBarIconBrightness': systemNavigationBarIconBrightness?.toString(), | ||
| }; | ||
| } | ||
|
|
||
| /// Creates a copy of this theme with the given fields replaced with new values. | ||
| SystemUiOverlayStyle copyWith({ | ||
| Color systemNavigationBarColor, | ||
| Color systemNavigationBarDividerColor, | ||
| Color statusBarColor, | ||
| Brightness statusBarBrightness, | ||
| Brightness statusBarIconBrightness, | ||
| Brightness systemNavigationBarIconBrightness, | ||
| }) { | ||
| return new SystemUiOverlayStyle( | ||
| systemNavigationBarColor: systemNavigationBarColor ?? this.systemNavigationBarColor, | ||
| systemNavigationBarDividerColor: systemNavigationBarDividerColor ?? this.systemNavigationBarDividerColor, | ||
| statusBarColor: statusBarColor ?? this.statusBarColor, | ||
| statusBarIconBrightness: statusBarIconBrightness ?? this.statusBarIconBrightness, | ||
| statusBarBrightness: statusBarBrightness ?? this.statusBarBrightness, | ||
| systemNavigationBarIconBrightness: systemNavigationBarIconBrightness ?? this.systemNavigationBarIconBrightness, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode { | ||
| return hashValues( | ||
| systemNavigationBarColor, | ||
| systemNavigationBarDividerColor, | ||
| statusBarColor, | ||
| statusBarBrightness, | ||
| statusBarIconBrightness, | ||
| systemNavigationBarIconBrightness, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(dynamic other) { | ||
| if (other.runtimeType != runtimeType) | ||
| return false; | ||
| final SystemUiOverlayStyle typedOther = other; | ||
| return typedOther.systemNavigationBarColor == systemNavigationBarColor | ||
| && typedOther.systemNavigationBarDividerColor == systemNavigationBarDividerColor | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should be indented so that the expressions line up |
||
| && typedOther.statusBarColor == statusBarColor | ||
| && typedOther.statusBarIconBrightness == statusBarIconBrightness | ||
| && typedOther.statusBarBrightness == statusBarBrightness | ||
| && typedOther.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness; | ||
| } | ||
| } | ||
|
|
||
| List<String> _stringify(List<dynamic> list) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function could be written or just inlined as The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't write this code so I'm going to leave it as is |
||
|
|
@@ -193,14 +319,9 @@ class SystemChrome { | |
| scheduleMicrotask(() { | ||
| assert(_pendingStyle != null); | ||
| if (_pendingStyle != _latestStyle) { | ||
| // TODO(jonahwilliams): remove when rolling chrome change. | ||
| SystemChannels.platform.invokeMethod( | ||
| 'SystemChrome.setSystemUIOverlayStyle', | ||
| <String, dynamic>{ | ||
| 'statusBarBrightness': _pendingStyle == SystemUiOverlayStyle.light | ||
| ? 'Brightness.light' | ||
| : 'Brightness.dark', | ||
| } | ||
| _pendingStyle._toMap(), | ||
| ); | ||
| _latestStyle = _pendingStyle; | ||
| } | ||
|
|
||
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.
in general i wouldn't bother with this kind of TODO. Either we eventually add platform themes and remove it, or we don't and this TODO isn't necessary.
I recommend reserving TODOs for more fundamental things where we know there's a limitation to the current implementation but we are intentionally cutting corners for some reason (e.g. because we are waiting an upstream fix).