Unverified Commit a671b283 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

CupertinoDynamicColor and friends (#37719)

parent ffa37854
...@@ -18,6 +18,7 @@ export 'src/cupertino/colors.dart'; ...@@ -18,6 +18,7 @@ export 'src/cupertino/colors.dart';
export 'src/cupertino/date_picker.dart'; export 'src/cupertino/date_picker.dart';
export 'src/cupertino/dialog.dart'; export 'src/cupertino/dialog.dart';
export 'src/cupertino/icons.dart'; export 'src/cupertino/icons.dart';
export 'src/cupertino/interface_level.dart';
export 'src/cupertino/localizations.dart'; export 'src/cupertino/localizations.dart';
export 'src/cupertino/nav_bar.dart'; export 'src/cupertino/nav_bar.dart';
export 'src/cupertino/page_scaffold.dart'; export 'src/cupertino/page_scaffold.dart';
......
...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
import 'button.dart'; import 'button.dart';
import 'colors.dart'; import 'colors.dart';
import 'icons.dart'; import 'icons.dart';
import 'interface_level.dart';
import 'localizations.dart'; import 'localizations.dart';
import 'route.dart'; import 'route.dart';
import 'theme.dart'; import 'theme.dart';
...@@ -268,45 +269,51 @@ class _CupertinoAppState extends State<CupertinoApp> { ...@@ -268,45 +269,51 @@ class _CupertinoAppState extends State<CupertinoApp> {
return ScrollConfiguration( return ScrollConfiguration(
behavior: _AlwaysCupertinoScrollBehavior(), behavior: _AlwaysCupertinoScrollBehavior(),
child: CupertinoTheme( child: CupertinoUserInterfaceLevel(
data: effectiveThemeData, data: CupertinoUserInterfaceLevelData.base,
child: WidgetsApp( child: CupertinoTheme(
key: GlobalObjectKey(this), data: effectiveThemeData,
navigatorKey: widget.navigatorKey, child: CupertinoSystemColors(
navigatorObservers: _navigatorObservers, data: CupertinoSystemColors.of(context, useFallbackValues: true),
pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) => child: WidgetsApp(
CupertinoPageRoute<T>(settings: settings, builder: builder), key: GlobalObjectKey(this),
home: widget.home, navigatorKey: widget.navigatorKey,
routes: widget.routes, navigatorObservers: _navigatorObservers,
initialRoute: widget.initialRoute, pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) =>
onGenerateRoute: widget.onGenerateRoute, CupertinoPageRoute<T>(settings: settings, builder: builder),
onUnknownRoute: widget.onUnknownRoute, home: widget.home,
builder: widget.builder, routes: widget.routes,
title: widget.title, initialRoute: widget.initialRoute,
onGenerateTitle: widget.onGenerateTitle, onGenerateRoute: widget.onGenerateRoute,
textStyle: effectiveThemeData.textTheme.textStyle, onUnknownRoute: widget.onUnknownRoute,
color: widget.color ?? CupertinoColors.activeBlue, builder: widget.builder,
locale: widget.locale, title: widget.title,
localizationsDelegates: _localizationsDelegates, onGenerateTitle: widget.onGenerateTitle,
localeResolutionCallback: widget.localeResolutionCallback, textStyle: effectiveThemeData.textTheme.textStyle,
localeListResolutionCallback: widget.localeListResolutionCallback, color: widget.color ?? CupertinoColors.activeBlue,
supportedLocales: widget.supportedLocales, locale: widget.locale,
showPerformanceOverlay: widget.showPerformanceOverlay, localizationsDelegates: _localizationsDelegates,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, localeResolutionCallback: widget.localeResolutionCallback,
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers, localeListResolutionCallback: widget.localeListResolutionCallback,
showSemanticsDebugger: widget.showSemanticsDebugger, supportedLocales: widget.supportedLocales,
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner, showPerformanceOverlay: widget.showPerformanceOverlay,
inspectorSelectButtonBuilder: (BuildContext context, VoidCallback onPressed) { checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
return CupertinoButton.filled( checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
child: const Icon( showSemanticsDebugger: widget.showSemanticsDebugger,
CupertinoIcons.search, debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
size: 28.0, inspectorSelectButtonBuilder: (BuildContext context, VoidCallback onPressed) {
color: CupertinoColors.white, return CupertinoButton.filled(
), child: const Icon(
padding: EdgeInsets.zero, CupertinoIcons.search,
onPressed: onPressed, size: 28.0,
); color: CupertinoColors.white,
}, ),
padding: EdgeInsets.zero,
onPressed: onPressed,
);
},
),
),
), ),
), ),
); );
......
// Copyright 2019 The Chromium 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 '../widgets/framework.dart';
/// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel`
/// from `UIKit`.
///
/// See also:
///
/// * `UIUserInterfaceLevel`, the UIKit equivalent: https://developer.apple.com/documentation/uikit/uiuserinterfacelevel.
enum CupertinoUserInterfaceLevelData {
/// The level for your window's main content.
base,
/// The level for content visually above [base].
elevated,
}
/// Establishes a subtree in which [CupertinoUserInterfaceLevel.of] resolves to
/// the given data.
///
/// Querying the current elevation status using [CupertinoUserInterfaceLevel.of]
/// will cause your widget to rebuild automatically whenever the [CupertinoUserInterfaceLevelData]
/// changes.
///
/// If no [CupertinoUserInterfaceLevel] is in scope then the [CupertinoUserInterfaceLevel.of]
/// method will throw an exception, unless the `nullOk` argument is set to true,
/// in which case it returns null.
///
/// See also:
///
/// * [CupertinoUserInterfaceLevelData], specifies the visual level for the content
/// in the subtree [CupertinoUserInterfaceLevel] established.
class CupertinoUserInterfaceLevel extends InheritedWidget {
/// Creates a [CupertinoUserInterfaceLevel] to change descendant Cupertino widget's
/// visual level.
const CupertinoUserInterfaceLevel({
Key key,
@required CupertinoUserInterfaceLevelData data,
Widget child,
}) : assert(data != null),
_data = data,
super(key: key, child: child);
final CupertinoUserInterfaceLevelData _data;
@override
bool updateShouldNotify(CupertinoUserInterfaceLevel oldWidget) => oldWidget._data != _data;
/// The data from the closest instance of this class that encloses the given
/// context.
///
/// You can use this function to query the user interface elevation level within
/// the given [BuildContext]. When that information changes, your widget will
/// be scheduled to be rebuilt, keeping your widget up-to-date.
static CupertinoUserInterfaceLevelData of(BuildContext context, { bool nullOk = false }) {
assert(context != null);
assert(nullOk != null);
final CupertinoUserInterfaceLevel query = context.inheritFromWidgetOfExactType(CupertinoUserInterfaceLevel);
if (query != null)
return query._data;
if (nullOk)
return null;
throw FlutterError(
'CupertinoUserInterfaceLevel.of() called with a context that does not contain a CupertinoUserInterfaceLevel.\n'
'No CupertinoUserInterfaceLevel ancestor could be found starting from the context that was passed '
'to CupertinoUserInterfaceLevel.of(). This can happen because you do not have a WidgetsApp or '
'MaterialApp widget (those widgets introduce a CupertinoUserInterfaceLevel), or it can happen '
'if the context you use comes from a widget above those widgets.\n'
'The context used was:\n'
' $context'
);
}
}
...@@ -9,6 +9,7 @@ import 'package:flutter/gestures.dart'; ...@@ -9,6 +9,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'theme.dart'; import 'theme.dart';
import 'thumb_painter.dart'; import 'thumb_painter.dart';
...@@ -228,7 +229,10 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt ...@@ -228,7 +229,10 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt
return _CupertinoSliderRenderObjectWidget( return _CupertinoSliderRenderObjectWidget(
value: (widget.value - widget.min) / (widget.max - widget.min), value: (widget.value - widget.min) / (widget.max - widget.min),
divisions: widget.divisions, divisions: widget.divisions,
activeColor: widget.activeColor ?? CupertinoTheme.of(context).primaryColor, activeColor: CupertinoDynamicColor.resolve(
widget.activeColor ?? CupertinoTheme.of(context).primaryColor,
context
),
onChanged: widget.onChanged != null ? _handleChanged : null, onChanged: widget.onChanged != null ? _handleChanged : null,
onChangeStart: widget.onChangeStart != null ? _handleDragStart : null, onChangeStart: widget.onChangeStart != null ? _handleDragStart : null,
onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null, onChangeEnd: widget.onChangeEnd != null ? _handleDragEnd : null,
...@@ -257,12 +261,14 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -257,12 +261,14 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
final ValueChanged<double> onChangeEnd; final ValueChanged<double> onChangeEnd;
final TickerProvider vsync; final TickerProvider vsync;
@override @override
_RenderCupertinoSlider createRenderObject(BuildContext context) { _RenderCupertinoSlider createRenderObject(BuildContext context) {
return _RenderCupertinoSlider( return _RenderCupertinoSlider(
value: value, value: value,
divisions: divisions, divisions: divisions,
activeColor: activeColor, activeColor: activeColor,
trackColor: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).systemFill, context),
onChanged: onChanged, onChanged: onChanged,
onChangeStart: onChangeStart, onChangeStart: onChangeStart,
onChangeEnd: onChangeEnd, onChangeEnd: onChangeEnd,
...@@ -277,6 +283,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -277,6 +283,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
..value = value ..value = value
..divisions = divisions ..divisions = divisions
..activeColor = activeColor ..activeColor = activeColor
..trackColor = CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).systemFill, context)
..onChanged = onChanged ..onChanged = onChanged
..onChangeStart = onChangeStart ..onChangeStart = onChangeStart
..onChangeEnd = onChangeEnd ..onChangeEnd = onChangeEnd
...@@ -287,7 +294,6 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget { ...@@ -287,7 +294,6 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
} }
const double _kPadding = 8.0; const double _kPadding = 8.0;
const Color _kTrackColor = Color(0xFFB5B5B5);
const double _kSliderHeight = 2.0 * (CupertinoThumbPainter.radius + _kPadding); const double _kSliderHeight = 2.0 * (CupertinoThumbPainter.radius + _kPadding);
const double _kSliderWidth = 176.0; // Matches Material Design slider. const double _kSliderWidth = 176.0; // Matches Material Design slider.
const Duration _kDiscreteTransitionDuration = Duration(milliseconds: 500); const Duration _kDiscreteTransitionDuration = Duration(milliseconds: 500);
...@@ -299,6 +305,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { ...@@ -299,6 +305,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
@required double value, @required double value,
int divisions, int divisions,
Color activeColor, Color activeColor,
Color trackColor,
ValueChanged<double> onChanged, ValueChanged<double> onChanged,
this.onChangeStart, this.onChangeStart,
this.onChangeEnd, this.onChangeEnd,
...@@ -309,6 +316,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { ...@@ -309,6 +316,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
_value = value, _value = value,
_divisions = divisions, _divisions = divisions,
_activeColor = activeColor, _activeColor = activeColor,
_trackColor = trackColor,
_onChanged = onChanged, _onChanged = onChanged,
_textDirection = textDirection, _textDirection = textDirection,
super(additionalConstraints: const BoxConstraints.tightFor(width: _kSliderWidth, height: _kSliderHeight)) { super(additionalConstraints: const BoxConstraints.tightFor(width: _kSliderWidth, height: _kSliderHeight)) {
...@@ -355,6 +363,15 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { ...@@ -355,6 +363,15 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
markNeedsPaint(); markNeedsPaint();
} }
Color get trackColor => _trackColor;
Color _trackColor;
set trackColor(Color value) {
if (value == _trackColor)
return;
_trackColor = value;
markNeedsPaint();
}
ValueChanged<double> get onChanged => _onChanged; ValueChanged<double> get onChanged => _onChanged;
ValueChanged<double> _onChanged; ValueChanged<double> _onChanged;
set onChanged(ValueChanged<double> value) { set onChanged(ValueChanged<double> value) {
...@@ -468,11 +485,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { ...@@ -468,11 +485,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
case TextDirection.rtl: case TextDirection.rtl:
visualPosition = 1.0 - _position.value; visualPosition = 1.0 - _position.value;
leftColor = _activeColor; leftColor = _activeColor;
rightColor = _kTrackColor; rightColor = trackColor;
break; break;
case TextDirection.ltr: case TextDirection.ltr:
visualPosition = _position.value; visualPosition = _position.value;
leftColor = _kTrackColor; leftColor = trackColor;
rightColor = _activeColor; rightColor = _activeColor;
break; break;
} }
......
...@@ -213,6 +213,32 @@ class CupertinoTextThemeData extends Diagnosticable { ...@@ -213,6 +213,32 @@ class CupertinoTextThemeData extends Diagnosticable {
(_isLight ? _kDefaultDateTimePickerLightTextStyle : _kDefaultDateTimePickerDarkTextStyle); (_isLight ? _kDefaultDateTimePickerLightTextStyle : _kDefaultDateTimePickerDarkTextStyle);
} }
/// Returns a copy of the current [CupertinoTextThemeData] with all the colors
/// resolved against the given [BuildContext].
CupertinoTextThemeData resolveFrom(BuildContext context, { bool nullOk = false }) {
Color convertColor(Color color) => color == null ? null : CupertinoDynamicColor.resolve(color, context, nullOk: nullOk);
TextStyle resolveTextStyle(TextStyle textStyle) {
return textStyle?.copyWith(
color: convertColor(textStyle.color),
backgroundColor: convertColor(textStyle.backgroundColor),
decorationColor: convertColor(textStyle.decorationColor),
);
}
return copyWith(
primaryColor: convertColor(_primaryColor),
textStyle: resolveTextStyle(_textStyle),
actionTextStyle: resolveTextStyle(_actionTextStyle),
tabLabelTextStyle: resolveTextStyle(_tabLabelTextStyle),
navTitleTextStyle : resolveTextStyle(_navTitleTextStyle),
navLargeTitleTextStyle: resolveTextStyle(_navLargeTitleTextStyle),
navActionTextStyle: resolveTextStyle(_navActionTextStyle),
pickerTextStyle: resolveTextStyle(_pickerTextStyle),
dateTimePickerTextStyle: resolveTextStyle(_dateTimePickerTextStyle),
);
}
/// Returns a copy of the current [CupertinoTextThemeData] instance with /// Returns a copy of the current [CupertinoTextThemeData] instance with
/// specified overrides. /// specified overrides.
CupertinoTextThemeData copyWith({ CupertinoTextThemeData copyWith({
......
...@@ -54,7 +54,20 @@ class CupertinoTheme extends StatelessWidget { ...@@ -54,7 +54,20 @@ class CupertinoTheme extends StatelessWidget {
/// exist in the ancestry tree. /// exist in the ancestry tree.
static CupertinoThemeData of(BuildContext context) { static CupertinoThemeData of(BuildContext context) {
final _InheritedCupertinoTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedCupertinoTheme); final _InheritedCupertinoTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedCupertinoTheme);
return inheritedTheme?.theme?.data ?? const CupertinoThemeData(); return (inheritedTheme?.theme?.data ?? const CupertinoThemeData()).resolveFrom(context, nullOk: true);
}
/// Retrieve the [Brightness] value from the closest ancestor [CupertinoTheme]
/// widget.
///
/// If no ancestral [CupertinoTheme] widget with explicit brightness value could
/// be found, the method will resort to the closest ancestor [MediaQuery] widget.
///
/// Throws an exception if no such [CupertinoTheme] or [MediaQuery] widgets exist
/// in the ancestry tree, unless [nullOk] is set to true.
static Brightness brightnessOf(BuildContext context, { bool nullOk = false }) {
final _InheritedCupertinoTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedCupertinoTheme);
return inheritedTheme?.theme?.data?._brightness ?? MediaQuery.of(context, nullOk: nullOk)?.platformBrightness;
} }
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
...@@ -229,6 +242,23 @@ class CupertinoThemeData extends Diagnosticable { ...@@ -229,6 +242,23 @@ class CupertinoThemeData extends Diagnosticable {
); );
} }
/// Return a new `CupertinoThemeData` whose colors are from this `CupertinoThemeData`,
/// but resolved aginst the given [BuildContext].
///
/// It will be called in [CupertinoTheme.of].
@protected
CupertinoThemeData resolveFrom(BuildContext context, { bool nullOk = false }) {
Color convertColor(Color color) => color == null ? null : CupertinoDynamicColor.resolve(color, context, nullOk: nullOk);
return copyWith(
primaryColor: convertColor(primaryColor),
primaryContrastingColor: convertColor(primaryContrastingColor),
textTheme: textTheme?.resolveFrom(context, nullOk: nullOk),
barBackgroundColor: convertColor(barBackgroundColor),
scaffoldBackgroundColor: convertColor(scaffoldBackgroundColor),
);
}
/// Create a copy of [CupertinoThemeData] with specified attributes overridden. /// Create a copy of [CupertinoThemeData] with specified attributes overridden.
/// ///
/// Only the current instance's specified attributes are copied instead of /// Only the current instance's specified attributes are copied instead of
...@@ -296,4 +326,39 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData { ...@@ -296,4 +326,39 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData {
final Color barBackgroundColor; final Color barBackgroundColor;
@override @override
final Color scaffoldBackgroundColor; final Color scaffoldBackgroundColor;
@override
_NoDefaultCupertinoThemeData resolveFrom(BuildContext context, { bool nullOk = false }) {
Color convertColor(Color color) => color == null
? null
: CupertinoDynamicColor.resolve(color, context, nullOk: nullOk);
return _NoDefaultCupertinoThemeData(
brightness,
convertColor(primaryColor),
convertColor(primaryContrastingColor),
textTheme?.resolveFrom(context, nullOk: nullOk),
convertColor(barBackgroundColor),
convertColor(scaffoldBackgroundColor),
);
}
@override
CupertinoThemeData copyWith({
Brightness brightness,
Color primaryColor,
Color primaryContrastingColor,
CupertinoTextThemeData textTheme,
Color barBackgroundColor ,
Color scaffoldBackgroundColor
}) {
return _NoDefaultCupertinoThemeData(
brightness ?? this.brightness,
primaryColor ?? this.primaryColor,
primaryContrastingColor ?? this.primaryContrastingColor,
textTheme ?? this.textTheme,
barBackgroundColor ?? this.barBackgroundColor,
scaffoldBackgroundColor ?? this.scaffoldBackgroundColor,
);
}
} }
...@@ -1416,34 +1416,43 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData { ...@@ -1416,34 +1416,43 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
/// ///
/// The [materialTheme] parameter must not be null. /// The [materialTheme] parameter must not be null.
MaterialBasedCupertinoThemeData({ MaterialBasedCupertinoThemeData({
@required ThemeData materialTheme, @required ThemeData materialTheme,
}) : assert(materialTheme != null), }) : this._(
_materialTheme = materialTheme, materialTheme,
// Pass all values to the superclass so Material-agnostic properties (materialTheme.cupertinoOverrideTheme ?? const CupertinoThemeData()).noDefault(),
// like barBackgroundColor can still behave like a normal );
// CupertinoThemeData.
super.raw( MaterialBasedCupertinoThemeData._(
materialTheme.cupertinoOverrideTheme?.brightness, this._materialTheme,
materialTheme.cupertinoOverrideTheme?.primaryColor, this._cupertinoOverrideTheme,
materialTheme.cupertinoOverrideTheme?.primaryContrastingColor, ) : assert(_materialTheme != null),
materialTheme.cupertinoOverrideTheme?.textTheme, assert(_cupertinoOverrideTheme != null),
materialTheme.cupertinoOverrideTheme?.barBackgroundColor, // Pass all values to the superclass so Material-agnostic properties
materialTheme.cupertinoOverrideTheme?.scaffoldBackgroundColor, // like barBackgroundColor can still behave like a normal
); // CupertinoThemeData.
super.raw(
_cupertinoOverrideTheme.brightness,
_cupertinoOverrideTheme.primaryColor,
_cupertinoOverrideTheme.primaryContrastingColor,
_cupertinoOverrideTheme.textTheme,
_cupertinoOverrideTheme.barBackgroundColor,
_cupertinoOverrideTheme.scaffoldBackgroundColor,
);
final ThemeData _materialTheme; final ThemeData _materialTheme;
final CupertinoThemeData _cupertinoOverrideTheme;
@override @override
Brightness get brightness => _materialTheme.cupertinoOverrideTheme?.brightness ?? _materialTheme.brightness; Brightness get brightness => _cupertinoOverrideTheme.brightness ?? _materialTheme.brightness;
@override @override
Color get primaryColor => _materialTheme.cupertinoOverrideTheme?.primaryColor ?? _materialTheme.colorScheme.primary; Color get primaryColor => _cupertinoOverrideTheme.primaryColor ?? _materialTheme.colorScheme.primary;
@override @override
Color get primaryContrastingColor => _materialTheme.cupertinoOverrideTheme?.primaryContrastingColor ?? _materialTheme.colorScheme.onPrimary; Color get primaryContrastingColor => _cupertinoOverrideTheme.primaryContrastingColor ?? _materialTheme.colorScheme.onPrimary;
@override @override
Color get scaffoldBackgroundColor => _materialTheme.cupertinoOverrideTheme?.scaffoldBackgroundColor ?? _materialTheme.scaffoldBackgroundColor; Color get scaffoldBackgroundColor => _cupertinoOverrideTheme.scaffoldBackgroundColor ?? _materialTheme.scaffoldBackgroundColor;
/// Copies the [ThemeData]'s `cupertinoOverrideTheme`. /// Copies the [ThemeData]'s `cupertinoOverrideTheme`.
/// ///
...@@ -1457,7 +1466,7 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData { ...@@ -1457,7 +1466,7 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
/// new Material [Theme] and use `copyWith` on the Material [ThemeData] /// new Material [Theme] and use `copyWith` on the Material [ThemeData]
/// instead. /// instead.
@override @override
CupertinoThemeData copyWith({ MaterialBasedCupertinoThemeData copyWith({
Brightness brightness, Brightness brightness,
Color primaryColor, Color primaryColor,
Color primaryContrastingColor, Color primaryContrastingColor,
...@@ -1465,20 +1474,26 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData { ...@@ -1465,20 +1474,26 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
Color barBackgroundColor, Color barBackgroundColor,
Color scaffoldBackgroundColor, Color scaffoldBackgroundColor,
}) { }) {
return _materialTheme.cupertinoOverrideTheme?.copyWith( return MaterialBasedCupertinoThemeData._(
brightness: brightness, _materialTheme,
primaryColor: primaryColor, _cupertinoOverrideTheme.copyWith(
primaryContrastingColor: primaryContrastingColor, brightness: brightness,
textTheme: textTheme, primaryColor: primaryColor,
barBackgroundColor: barBackgroundColor, primaryContrastingColor: primaryContrastingColor,
scaffoldBackgroundColor: scaffoldBackgroundColor, textTheme: textTheme,
) ?? CupertinoThemeData( barBackgroundColor: barBackgroundColor,
brightness: brightness, scaffoldBackgroundColor: scaffoldBackgroundColor,
primaryColor: primaryColor, ),
primaryContrastingColor: primaryContrastingColor, );
textTheme: textTheme, }
barBackgroundColor: barBackgroundColor,
scaffoldBackgroundColor: scaffoldBackgroundColor, @override
CupertinoThemeData resolveFrom(BuildContext context, { bool nullOk = false }) {
// Only the cupertino override theme part will be resolved.
// If the color comes from the material theme it's not resolved.
return MaterialBasedCupertinoThemeData._(
_materialTheme,
_cupertinoOverrideTheme.resolveFrom(context, nullOk: nullOk),
); );
} }
} }
......
...@@ -98,6 +98,7 @@ class MediaQueryData { ...@@ -98,6 +98,7 @@ class MediaQueryData {
this.alwaysUse24HourFormat = false, this.alwaysUse24HourFormat = false,
this.accessibleNavigation = false, this.accessibleNavigation = false,
this.invertColors = false, this.invertColors = false,
this.highContrast = false,
this.disableAnimations = false, this.disableAnimations = false,
this.boldText = false, this.boldText = false,
}); });
...@@ -121,6 +122,7 @@ class MediaQueryData { ...@@ -121,6 +122,7 @@ class MediaQueryData {
invertColors = window.accessibilityFeatures.invertColors, invertColors = window.accessibilityFeatures.invertColors,
disableAnimations = window.accessibilityFeatures.disableAnimations, disableAnimations = window.accessibilityFeatures.disableAnimations,
boldText = window.accessibilityFeatures.boldText, boldText = window.accessibilityFeatures.boldText,
highContrast = false,
alwaysUse24HourFormat = window.alwaysUse24HourFormat; alwaysUse24HourFormat = window.alwaysUse24HourFormat;
/// The size of the media in logical pixels (e.g, the size of the screen). /// The size of the media in logical pixels (e.g, the size of the screen).
...@@ -259,6 +261,13 @@ class MediaQueryData { ...@@ -259,6 +261,13 @@ class MediaQueryData {
/// * [Window.AccessibilityFeatures], where the setting originates. /// * [Window.AccessibilityFeatures], where the setting originates.
final bool invertColors; final bool invertColors;
/// Whether the user requested a high contrast between foreground and background
/// content on iOS, via Settings -> Accessibility -> Increase Contrast.
///
/// This flag is currently only updated on iOS devices that are running iOS 13
/// or above.
final bool highContrast;
/// Whether the platform is requesting that animations be disabled or reduced /// Whether the platform is requesting that animations be disabled or reduced
/// as much as possible. /// as much as possible.
/// ///
...@@ -293,6 +302,7 @@ class MediaQueryData { ...@@ -293,6 +302,7 @@ class MediaQueryData {
EdgeInsets viewInsets, EdgeInsets viewInsets,
double physicalDepth, double physicalDepth,
bool alwaysUse24HourFormat, bool alwaysUse24HourFormat,
bool highContrast,
bool disableAnimations, bool disableAnimations,
bool invertColors, bool invertColors,
bool accessibleNavigation, bool accessibleNavigation,
...@@ -309,6 +319,7 @@ class MediaQueryData { ...@@ -309,6 +319,7 @@ class MediaQueryData {
physicalDepth: physicalDepth ?? this.physicalDepth, physicalDepth: physicalDepth ?? this.physicalDepth,
alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat,
invertColors: invertColors ?? this.invertColors, invertColors: invertColors ?? this.invertColors,
highContrast: highContrast ?? this.highContrast,
disableAnimations: disableAnimations ?? this.disableAnimations, disableAnimations: disableAnimations ?? this.disableAnimations,
accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation, accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation,
boldText: boldText ?? this.boldText, boldText: boldText ?? this.boldText,
...@@ -357,6 +368,7 @@ class MediaQueryData { ...@@ -357,6 +368,7 @@ class MediaQueryData {
), ),
viewInsets: viewInsets, viewInsets: viewInsets,
alwaysUse24HourFormat: alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat,
highContrast: highContrast,
disableAnimations: disableAnimations, disableAnimations: disableAnimations,
invertColors: invertColors, invertColors: invertColors,
accessibleNavigation: accessibleNavigation, accessibleNavigation: accessibleNavigation,
...@@ -404,6 +416,7 @@ class MediaQueryData { ...@@ -404,6 +416,7 @@ class MediaQueryData {
bottom: removeBottom ? 0.0 : null, bottom: removeBottom ? 0.0 : null,
), ),
alwaysUse24HourFormat: alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat,
highContrast: highContrast,
disableAnimations: disableAnimations, disableAnimations: disableAnimations,
invertColors: invertColors, invertColors: invertColors,
accessibleNavigation: accessibleNavigation, accessibleNavigation: accessibleNavigation,
...@@ -451,6 +464,7 @@ class MediaQueryData { ...@@ -451,6 +464,7 @@ class MediaQueryData {
bottom: removeBottom ? 0.0 : null, bottom: removeBottom ? 0.0 : null,
), ),
alwaysUse24HourFormat: alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat,
highContrast: highContrast,
disableAnimations: disableAnimations, disableAnimations: disableAnimations,
invertColors: invertColors, invertColors: invertColors,
accessibleNavigation: accessibleNavigation, accessibleNavigation: accessibleNavigation,
...@@ -472,6 +486,7 @@ class MediaQueryData { ...@@ -472,6 +486,7 @@ class MediaQueryData {
&& typedOther.viewInsets == viewInsets && typedOther.viewInsets == viewInsets
&& typedOther.physicalDepth == physicalDepth && typedOther.physicalDepth == physicalDepth
&& typedOther.alwaysUse24HourFormat == alwaysUse24HourFormat && typedOther.alwaysUse24HourFormat == alwaysUse24HourFormat
&& typedOther.highContrast == highContrast
&& typedOther.disableAnimations == disableAnimations && typedOther.disableAnimations == disableAnimations
&& typedOther.invertColors == invertColors && typedOther.invertColors == invertColors
&& typedOther.accessibleNavigation == accessibleNavigation && typedOther.accessibleNavigation == accessibleNavigation
...@@ -490,6 +505,7 @@ class MediaQueryData { ...@@ -490,6 +505,7 @@ class MediaQueryData {
viewInsets, viewInsets,
physicalDepth, physicalDepth,
alwaysUse24HourFormat, alwaysUse24HourFormat,
highContrast,
disableAnimations, disableAnimations,
invertColors, invertColors,
accessibleNavigation, accessibleNavigation,
...@@ -510,6 +526,7 @@ class MediaQueryData { ...@@ -510,6 +526,7 @@ class MediaQueryData {
'physicalDepth: $physicalDepth, ' 'physicalDepth: $physicalDepth, '
'alwaysUse24HourFormat: $alwaysUse24HourFormat, ' 'alwaysUse24HourFormat: $alwaysUse24HourFormat, '
'accessibleNavigation: $accessibleNavigation, ' 'accessibleNavigation: $accessibleNavigation, '
'highContrast: $highContrast,'
'disableAnimations: $disableAnimations, ' 'disableAnimations: $disableAnimations, '
'invertColors: $invertColors, ' 'invertColors: $invertColors, '
'boldText: $boldText' 'boldText: $boldText'
......
This diff is collapsed.
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