diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 4013a6aff1..2b68c93a71 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -294,9 +294,18 @@ Widget _wrapWithBackground({ ); final bool darkBackground = backgroundColor.computeLuminance() < 0.179; - SystemChrome.setSystemUIOverlayStyle( - darkBackground ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark - ); + // TODO(jonahwilliams): remove once we have platform themes. + 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) return childWithBackground; diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index b12f45aa0f..eb1504c83b 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -346,9 +346,17 @@ class _AppBarState extends State { TextStyle sideStyle = widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1; final Brightness brightness = widget.brightness ?? themeData.primaryColorBrightness; - SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark - ? SystemUiOverlayStyle.light - : SystemUiOverlayStyle.dark); + // TODO(jonahwilliams): remove once we have platform themes. + switch (defaultTargetPlatform) { + 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) { final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity); diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index c0ae600411..dc565bf5ed 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -5,6 +5,7 @@ import 'dart:ui' show Color, hashValues; import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'button_theme.dart'; @@ -16,20 +17,7 @@ import 'input_decorator.dart'; import 'slider_theme.dart'; import 'typography.dart'; -/// 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, -} +export 'package:flutter/services.dart' show Brightness; // 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 diff --git a/packages/flutter/lib/src/services/system_chrome.dart b/packages/flutter/lib/src/services/system_chrome.dart index da2d6580d2..622b890b1b 100644 --- a/packages/flutter/lib/src/services/system_chrome.dart +++ b/packages/flutter/lib/src/services/system_chrome.dart @@ -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, + 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 _toMap() { + return { + '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 _stringify(List list) { @@ -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', - { - 'statusBarBrightness': _pendingStyle == SystemUiOverlayStyle.light - ? 'Brightness.light' - : 'Brightness.dark', - } + _pendingStyle._toMap(), ); _latestStyle = _pendingStyle; }