Unverified Commit 57322195 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Extend SystemUiOverlayStyle with additonal values for each platform (#17171)

parent f48dec57
...@@ -294,9 +294,18 @@ Widget _wrapWithBackground({ ...@@ -294,9 +294,18 @@ Widget _wrapWithBackground({
); );
final bool darkBackground = backgroundColor.computeLuminance() < 0.179; final bool darkBackground = backgroundColor.computeLuminance() < 0.179;
SystemChrome.setSystemUIOverlayStyle( // TODO(jonahwilliams): remove once we have platform themes.
darkBackground ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark switch (defaultTargetPlatform) {
); case TargetPlatform.iOS:
SystemChrome.setSystemUIOverlayStyle(
darkBackground ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark
);
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
}
if (backgroundColor.alpha == 0xFF) if (backgroundColor.alpha == 0xFF)
return childWithBackground; return childWithBackground;
......
...@@ -346,9 +346,17 @@ class _AppBarState extends State<AppBar> { ...@@ -346,9 +346,17 @@ class _AppBarState extends State<AppBar> {
TextStyle sideStyle = widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1; TextStyle sideStyle = widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1;
final Brightness brightness = widget.brightness ?? themeData.primaryColorBrightness; final Brightness brightness = widget.brightness ?? themeData.primaryColorBrightness;
SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark // TODO(jonahwilliams): remove once we have platform themes.
? SystemUiOverlayStyle.light switch (defaultTargetPlatform) {
: SystemUiOverlayStyle.dark); case TargetPlatform.iOS:
SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark);
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
}
if (widget.toolbarOpacity != 1.0) { if (widget.toolbarOpacity != 1.0) {
final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity); final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:ui' show Color, hashValues; import 'dart:ui' show Color, hashValues;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'button_theme.dart'; import 'button_theme.dart';
...@@ -16,20 +17,7 @@ import 'input_decorator.dart'; ...@@ -16,20 +17,7 @@ import 'input_decorator.dart';
import 'slider_theme.dart'; import 'slider_theme.dart';
import 'typography.dart'; import 'typography.dart';
/// Describes the contrast needs of a color. export 'package:flutter/services.dart' show Brightness;
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,
}
// Deriving these values is black magic. The spec claims that pressed buttons // Deriving these values is black magic. The spec claims that pressed buttons
// have a highlight of 0x66999999, but that's clearly wrong. The videos in the // have a highlight of 0x66999999, but that's clearly wrong. The videos in the
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -77,17 +78,142 @@ enum SystemUiOverlay { ...@@ -77,17 +78,142 @@ enum SystemUiOverlay {
bottom, 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. /// Specifies a preference for the style of the system overlays.
/// ///
/// Used by [SystemChrome.setSystemUIOverlayStyle]. /// Used by [SystemChrome.setSystemUIOverlayStyle].
enum SystemUiOverlayStyle { class SystemUiOverlayStyle {
/// System overlays should be drawn with a light color. Intended for /// System overlays should be drawn with a light color. Intended for
/// applications with a dark background. /// applications with a dark background.
light, static const SystemUiOverlayStyle light = const SystemUiOverlayStyle(
systemNavigationBarColor: const Color(0xFFFFFFFF),
systemNavigationBarDividerColor: null,
statusBarColor: null,
systemNavigationBarIconBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark,
);
/// System overlays should be drawn with a dark color. Intended for /// System overlays should be drawn with a dark color. Intended for
/// applications with a light background. /// 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
&& typedOther.statusBarColor == statusBarColor
&& typedOther.statusBarIconBrightness == statusBarIconBrightness
&& typedOther.statusBarBrightness == statusBarBrightness
&& typedOther.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness;
}
} }
List<String> _stringify(List<dynamic> list) { List<String> _stringify(List<dynamic> list) {
...@@ -193,14 +319,9 @@ class SystemChrome { ...@@ -193,14 +319,9 @@ class SystemChrome {
scheduleMicrotask(() { scheduleMicrotask(() {
assert(_pendingStyle != null); assert(_pendingStyle != null);
if (_pendingStyle != _latestStyle) { if (_pendingStyle != _latestStyle) {
// TODO(jonahwilliams): remove when rolling chrome change.
SystemChannels.platform.invokeMethod( SystemChannels.platform.invokeMethod(
'SystemChrome.setSystemUIOverlayStyle', 'SystemChrome.setSystemUIOverlayStyle',
<String, dynamic>{ _pendingStyle._toMap(),
'statusBarBrightness': _pendingStyle == SystemUiOverlayStyle.light
? 'Brightness.light'
: 'Brightness.dark',
}
); );
_latestStyle = _pendingStyle; _latestStyle = _pendingStyle;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment