diff --git a/packages/flutter/lib/src/cupertino/colors.dart b/packages/flutter/lib/src/cupertino/colors.dart index e73485d164..ee82cef799 100644 --- a/packages/flutter/lib/src/cupertino/colors.dart +++ b/packages/flutter/lib/src/cupertino/colors.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' show Color, Brightness; import '../../foundation.dart'; @@ -683,15 +681,15 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// /// All the colors must not be null. const CupertinoDynamicColor({ - String debugLabel, - @required Color color, - @required Color darkColor, - @required Color highContrastColor, - @required Color darkHighContrastColor, - @required Color elevatedColor, - @required Color darkElevatedColor, - @required Color highContrastElevatedColor, - @required Color darkHighContrastElevatedColor, + String? debugLabel, + required Color color, + required Color darkColor, + required Color highContrastColor, + required Color darkHighContrastColor, + required Color elevatedColor, + required Color darkElevatedColor, + required Color highContrastElevatedColor, + required Color darkHighContrastElevatedColor, }) : this._( color, color, @@ -713,11 +711,11 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// /// All the colors must not be null. const CupertinoDynamicColor.withBrightnessAndContrast({ - String debugLabel, - @required Color color, - @required Color darkColor, - @required Color highContrastColor, - @required Color darkHighContrastColor, + String? debugLabel, + required Color color, + required Color darkColor, + required Color highContrastColor, + required Color darkHighContrastColor, }) : this( debugLabel: debugLabel, color: color, @@ -736,9 +734,9 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// /// All the colors must not be null. const CupertinoDynamicColor.withBrightness({ - String debugLabel, - @required Color color, - @required Color darkColor, + String? debugLabel, + required Color color, + required Color darkColor, }) : this( debugLabel: debugLabel, color: color, @@ -786,9 +784,9 @@ class CupertinoDynamicColor extends Color with Diagnosticable { @override int get value => _effectiveColor.value; - final String _debugLabel; + final String? _debugLabel; - final Element _debugResolveContext; + final Element? _debugResolveContext; /// The color to use when the [BuildContext] implies a combination of light mode, /// normal contrast, and base interface elevation. @@ -887,7 +885,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// value will be used ([Brightness.light] platform brightness, normal contrast, /// [CupertinoUserInterfaceLevelData.base] elevation level), unless [nullOk] is /// set to false, in which case an exception will be thrown. - static Color resolve(Color resolvable, BuildContext context, { bool nullOk = true }) { + static Color? resolve(Color? resolvable, BuildContext context, { bool nullOk = true }) { if (resolvable == null) return null; assert(context != null); @@ -981,7 +979,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable { } } - Element _debugContext; + Element? _debugContext; assert(() { _debugContext = context as Element; return true; @@ -1058,7 +1056,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); if (_debugLabel != null) - properties.add(MessageProperty('debugLabel', _debugLabel)); + properties.add(MessageProperty('debugLabel', _debugLabel!)); properties.add(createCupertinoColorProperty('color', color)); if (_isPlatformBrightnessDependent) properties.add(createCupertinoColorProperty('darkColor', darkColor)); @@ -1085,11 +1083,11 @@ class CupertinoDynamicColor extends Color with Diagnosticable { /// The [showName], [style], and [level] arguments must not be null. DiagnosticsProperty createCupertinoColorProperty( String name, - Color value, { - bool showName = true, - Object defaultValue = kNoDefaultValue, - DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, - DiagnosticLevel level = DiagnosticLevel.info, + Color? value, { + bool showName = true, + Object? defaultValue = kNoDefaultValue, + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, + DiagnosticLevel level = DiagnosticLevel.info, }) { if (value is CupertinoDynamicColor) { return DiagnosticsProperty( diff --git a/packages/flutter/lib/src/cupertino/icon_theme_data.dart b/packages/flutter/lib/src/cupertino/icon_theme_data.dart index 85dbde012e..15a14898e1 100644 --- a/packages/flutter/lib/src/cupertino/icon_theme_data.dart +++ b/packages/flutter/lib/src/cupertino/icon_theme_data.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'colors.dart'; @@ -16,22 +14,22 @@ class CupertinoIconThemeData extends IconThemeData with Diagnosticable { /// The opacity applies to both explicit and default icon colors. The value /// is clamped between 0.0 and 1.0. const CupertinoIconThemeData({ - Color color, - double opacity, - double size + Color? color, + double? opacity, + double? size, }) : super(color: color, opacity: opacity, size: size); /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext]. @override IconThemeData resolve(BuildContext context) { - final Color resolvedColor = CupertinoDynamicColor.resolve(color, context); + final Color? resolvedColor = CupertinoDynamicColor.resolve(color, context); return resolvedColor == color ? this : copyWith(color: resolvedColor); } /// Creates a copy of this icon theme but with the given fields replaced with /// the new values. @override - CupertinoIconThemeData copyWith({ Color color, double opacity, double size }) { + CupertinoIconThemeData copyWith({ Color? color, double? opacity, double? size }) { return CupertinoIconThemeData( color: color ?? this.color, opacity: opacity ?? this.opacity, diff --git a/packages/flutter/lib/src/cupertino/interface_level.dart b/packages/flutter/lib/src/cupertino/interface_level.dart index 328c08bd49..dba8054327 100644 --- a/packages/flutter/lib/src/cupertino/interface_level.dart +++ b/packages/flutter/lib/src/cupertino/interface_level.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import '../widgets/framework.dart'; @@ -41,9 +39,9 @@ class CupertinoUserInterfaceLevel extends InheritedWidget { /// Creates a [CupertinoUserInterfaceLevel] to change descendant Cupertino widget's /// visual level. const CupertinoUserInterfaceLevel({ - Key key, - @required CupertinoUserInterfaceLevelData data, - Widget child, + Key? key, + required CupertinoUserInterfaceLevelData data, + required Widget child, }) : assert(data != null), _data = data, super(key: key, child: child); @@ -59,10 +57,10 @@ class CupertinoUserInterfaceLevel extends InheritedWidget { /// 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 }) { + static CupertinoUserInterfaceLevelData? of(BuildContext context, { bool nullOk = false }) { assert(context != null); assert(nullOk != null); - final CupertinoUserInterfaceLevel query = context.dependOnInheritedWidgetOfExactType(); + final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType(); if (query != null) return query._data; if (nullOk) diff --git a/packages/flutter/lib/src/cupertino/text_theme.dart b/packages/flutter/lib/src/cupertino/text_theme.dart index 0cf125cca7..28f2afd80c 100644 --- a/packages/flutter/lib/src/cupertino/text_theme.dart +++ b/packages/flutter/lib/src/cupertino/text_theme.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart' show Brightness; import 'package:flutter/widgets.dart'; @@ -98,12 +96,12 @@ const TextStyle _kDefaultDateTimePickerTextStyle = TextStyle( color: CupertinoColors.label, ); -TextStyle _resolveTextStyle(TextStyle style, BuildContext context, bool nullOk) { +TextStyle? _resolveTextStyle(TextStyle? style, BuildContext context, bool nullOk) { // This does not resolve the shadow color, foreground, background, etc. return style?.copyWith( - color: CupertinoDynamicColor.resolve(style?.color, context, nullOk: nullOk), - backgroundColor: CupertinoDynamicColor.resolve(style?.backgroundColor, context, nullOk: nullOk), - decorationColor: CupertinoDynamicColor.resolve(style?.decorationColor, context, nullOk: nullOk), + color: CupertinoDynamicColor.resolve(style.color, context, nullOk: nullOk), + backgroundColor: CupertinoDynamicColor.resolve(style.backgroundColor, context, nullOk: nullOk), + decorationColor: CupertinoDynamicColor.resolve(style.decorationColor, context, nullOk: nullOk), ); } @@ -126,15 +124,15 @@ class CupertinoTextThemeData with Diagnosticable { 'This argument no longer does anything. You can remove it. ' 'This feature was deprecated after v1.10.14.' ) - Brightness brightness, - TextStyle textStyle, - TextStyle actionTextStyle, - TextStyle tabLabelTextStyle, - TextStyle navTitleTextStyle, - TextStyle navLargeTitleTextStyle, - TextStyle navActionTextStyle, - TextStyle pickerTextStyle, - TextStyle dateTimePickerTextStyle, + Brightness? brightness, + TextStyle? textStyle, + TextStyle? actionTextStyle, + TextStyle? tabLabelTextStyle, + TextStyle? navTitleTextStyle, + TextStyle? navLargeTitleTextStyle, + TextStyle? navActionTextStyle, + TextStyle? pickerTextStyle, + TextStyle? dateTimePickerTextStyle, }) : this._raw( const _TextThemeDefaultsBuilder(CupertinoColors.label, CupertinoColors.inactiveGray), primaryColor, @@ -162,41 +160,41 @@ class CupertinoTextThemeData with Diagnosticable { ) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null); final _TextThemeDefaultsBuilder _defaults; - final Color _primaryColor; + final Color? _primaryColor; - final TextStyle _textStyle; + final TextStyle? _textStyle; /// The [TextStyle] of general text content for Cupertino widgets. TextStyle get textStyle => _textStyle ?? _defaults.textStyle; - final TextStyle _actionTextStyle; + final TextStyle? _actionTextStyle; /// The [TextStyle] of interactive text content such as text in a button without background. TextStyle get actionTextStyle { return _actionTextStyle ?? _defaults.actionTextStyle(primaryColor: _primaryColor); } - final TextStyle _tabLabelTextStyle; + final TextStyle? _tabLabelTextStyle; /// The [TextStyle] of unselected tabs. TextStyle get tabLabelTextStyle => _tabLabelTextStyle ?? _defaults.tabLabelTextStyle; - final TextStyle _navTitleTextStyle; + final TextStyle? _navTitleTextStyle; /// The [TextStyle] of titles in standard navigation bars. TextStyle get navTitleTextStyle => _navTitleTextStyle ?? _defaults.navTitleTextStyle; - final TextStyle _navLargeTitleTextStyle; + final TextStyle? _navLargeTitleTextStyle; /// The [TextStyle] of large titles in sliver navigation bars. TextStyle get navLargeTitleTextStyle => _navLargeTitleTextStyle ?? _defaults.navLargeTitleTextStyle; - final TextStyle _navActionTextStyle; + final TextStyle? _navActionTextStyle; /// The [TextStyle] of interactive text content in navigation bars. TextStyle get navActionTextStyle { return _navActionTextStyle ?? _defaults.navActionTextStyle(primaryColor: _primaryColor); } - final TextStyle _pickerTextStyle; + final TextStyle? _pickerTextStyle; /// The [TextStyle] of pickers. TextStyle get pickerTextStyle => _pickerTextStyle ?? _defaults.pickerTextStyle; - final TextStyle _dateTimePickerTextStyle; + final TextStyle? _dateTimePickerTextStyle; /// The [TextStyle] of date time pickers. TextStyle get dateTimePickerTextStyle => _dateTimePickerTextStyle ?? _defaults.dateTimePickerTextStyle; @@ -209,7 +207,7 @@ class CupertinoTextThemeData with Diagnosticable { /// be used as-is. CupertinoTextThemeData resolveFrom(BuildContext context, { bool nullOk = false }) { return CupertinoTextThemeData._raw( - _defaults?.resolveFrom(context, nullOk), + _defaults.resolveFrom(context, nullOk), CupertinoDynamicColor.resolve(_primaryColor, context, nullOk: nullOk), _resolveTextStyle(_textStyle, context, nullOk), _resolveTextStyle(_actionTextStyle, context, nullOk), @@ -225,20 +223,20 @@ class CupertinoTextThemeData with Diagnosticable { /// Returns a copy of the current [CupertinoTextThemeData] instance with /// specified overrides. CupertinoTextThemeData copyWith({ - Color primaryColor, + Color? primaryColor, @Deprecated( 'This argument no longer does anything. You can remove it. ' 'This feature was deprecated after v1.10.14.' ) - Brightness brightness, - TextStyle textStyle, - TextStyle actionTextStyle, - TextStyle tabLabelTextStyle, - TextStyle navTitleTextStyle, - TextStyle navLargeTitleTextStyle, - TextStyle navActionTextStyle, - TextStyle pickerTextStyle, - TextStyle dateTimePickerTextStyle, + Brightness? brightness, + TextStyle? textStyle, + TextStyle? actionTextStyle, + TextStyle? tabLabelTextStyle, + TextStyle? navTitleTextStyle, + TextStyle? navLargeTitleTextStyle, + TextStyle? navActionTextStyle, + TextStyle? pickerTextStyle, + TextStyle? dateTimePickerTextStyle, }) { return CupertinoTextThemeData._raw( _defaults, @@ -282,9 +280,9 @@ class _TextThemeDefaultsBuilder { final Color inactiveGrayColor; static TextStyle _applyLabelColor(TextStyle original, Color color) { - return original?.color == color + return original.color == color ? original - : original?.copyWith(color: color); + : original.copyWith(color: color); } TextStyle get textStyle => _applyLabelColor(_kDefaultTextStyle, labelColor); @@ -294,12 +292,12 @@ class _TextThemeDefaultsBuilder { TextStyle get pickerTextStyle => _applyLabelColor(_kDefaultPickerTextStyle, labelColor); TextStyle get dateTimePickerTextStyle => _applyLabelColor(_kDefaultDateTimePickerTextStyle, labelColor); - TextStyle actionTextStyle({ Color primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor); - TextStyle navActionTextStyle({ Color primaryColor }) => actionTextStyle(primaryColor: primaryColor); + TextStyle actionTextStyle({ Color? primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor); + TextStyle navActionTextStyle({ Color? primaryColor }) => actionTextStyle(primaryColor: primaryColor); _TextThemeDefaultsBuilder resolveFrom(BuildContext context, bool nullOk) { - final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk); - final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context, nullOk: nullOk); + final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk)!; + final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context, nullOk: nullOk)!; return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray ? this : _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray); diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index f475e5c7f7..0da597968b 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -52,9 +50,9 @@ class CupertinoTheme extends StatelessWidget { /// /// The [data] and [child] parameters must not be null. const CupertinoTheme({ - Key key, - @required this.data, - @required this.child, + Key? key, + required this.data, + required this.child, }) : assert(child != null), assert(data != null), super(key: key); @@ -69,8 +67,8 @@ class CupertinoTheme extends StatelessWidget { /// Resolves all the colors defined in that [CupertinoThemeData] against the /// given [BuildContext] on a best-effort basis. static CupertinoThemeData of(BuildContext context) { - final _InheritedCupertinoTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); - return (inheritedTheme?.theme?.data ?? const CupertinoThemeData()).resolveFrom(context, nullOk: true); + final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); + return (inheritedTheme?.theme.data ?? const CupertinoThemeData()).resolveFrom(context, nullOk: true); } /// Retrieves the [Brightness] to use for descendant Cupertino widgets, based @@ -86,9 +84,9 @@ class CupertinoTheme extends StatelessWidget { /// /// * [CupertinoThemeData.brightness], the property takes precedence over /// [MediaQueryData.platformBrightness] for descendant Cupertino widgets. - static Brightness brightnessOf(BuildContext context, { bool nullOk = false }) { - final _InheritedCupertinoTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); - return inheritedTheme?.theme?.data?.brightness ?? MediaQuery.of(context, nullOk: nullOk)?.platformBrightness; + static Brightness? brightnessOf(BuildContext context, { bool nullOk = false }) { + final _InheritedCupertinoTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); + return inheritedTheme?.theme.data.brightness ?? MediaQuery.of(context, nullOk: nullOk)?.platformBrightness; } /// The widget below this widget in the tree. @@ -116,9 +114,9 @@ class CupertinoTheme extends StatelessWidget { class _InheritedCupertinoTheme extends InheritedWidget { const _InheritedCupertinoTheme({ - Key key, - @required this.theme, - @required Widget child, + Key? key, + required this.theme, + required Widget child, }) : assert(theme != null), super(key: key, child: child); @@ -150,12 +148,12 @@ class CupertinoThemeData with Diagnosticable { /// /// Unspecified parameters default to a reasonable iOS default style. const CupertinoThemeData({ - Brightness brightness, - Color primaryColor, - Color primaryContrastingColor, - CupertinoTextThemeData textTheme, - Color barBackgroundColor, - Color scaffoldBackgroundColor, + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, }) : this.raw( brightness, primaryColor, @@ -171,12 +169,12 @@ class CupertinoThemeData with Diagnosticable { /// Used by subclasses to get the superclass's defaulting behaviors. @protected const CupertinoThemeData.raw( - Brightness brightness, - Color primaryColor, - Color primaryContrastingColor, - CupertinoTextThemeData textTheme, - Color barBackgroundColor, - Color scaffoldBackgroundColor, + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, ) : this._rawWithDefaults( brightness, primaryColor, @@ -197,7 +195,7 @@ class CupertinoThemeData with Diagnosticable { this._defaults, ); - final _CupertinoThemeDefaults _defaults; + final _CupertinoThemeDefaults? _defaults; /// The brightness override for Cupertino descendants. /// @@ -215,7 +213,7 @@ class CupertinoThemeData with Diagnosticable { /// /// * [CupertinoTheme.brightnessOf], a method used to retrieve the overall /// [Brightness] from a [BuildContext], for Cupertino widgets. - final Brightness brightness; + final Brightness? brightness; /// A color used on interactive elements of the theme. /// @@ -232,8 +230,8 @@ class CupertinoThemeData with Diagnosticable { /// /// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers /// [primaryColor] to its Material [Theme] parent if it's unspecified. - Color get primaryColor => _primaryColor ?? _defaults.primaryColor; - final Color _primaryColor; + Color? get primaryColor => _primaryColor ?? _defaults!.primaryColor; + final Color? _primaryColor; /// A color that must be easy to see when rendered on a [primaryColor] background. /// @@ -247,29 +245,29 @@ class CupertinoThemeData with Diagnosticable { /// /// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers /// [primaryContrastingColor] to its Material [Theme] parent if it's unspecified. - Color get primaryContrastingColor => _primaryContrastingColor ?? _defaults.primaryContrastingColor; - final Color _primaryContrastingColor; + Color? get primaryContrastingColor => _primaryContrastingColor ?? _defaults!.primaryContrastingColor; + final Color? _primaryContrastingColor; /// Text styles used by Cupertino widgets. /// /// Derived from [primaryColor] if unspecified. - CupertinoTextThemeData get textTheme { - return _textTheme ?? _defaults.textThemeDefaults.createDefaults(primaryColor: primaryColor); + CupertinoTextThemeData? get textTheme { + return _textTheme ?? _defaults!.textThemeDefaults.createDefaults(primaryColor: primaryColor!); } - final CupertinoTextThemeData _textTheme; + final CupertinoTextThemeData? _textTheme; /// Background color of the top nav bar and bottom tab bar. /// /// Defaults to a light gray in light mode, or a dark translucent gray color in /// dark mode. - Color get barBackgroundColor => _barBackgroundColor ?? _defaults.barBackgroundColor; - final Color _barBackgroundColor; + Color? get barBackgroundColor => _barBackgroundColor ?? _defaults!.barBackgroundColor; + final Color? _barBackgroundColor; /// Background color of the scaffold. /// /// Defaults to [CupertinoColors.systemBackground]. - Color get scaffoldBackgroundColor => _scaffoldBackgroundColor ?? _defaults.scaffoldBackgroundColor; - final Color _scaffoldBackgroundColor; + Color? get scaffoldBackgroundColor => _scaffoldBackgroundColor ?? _defaults!.scaffoldBackgroundColor; + final Color? _scaffoldBackgroundColor; /// Returns an instance of the [CupertinoThemeData] whose property getters /// only return the construction time specifications with no derived values. @@ -294,7 +292,7 @@ class CupertinoThemeData with Diagnosticable { /// [CupertinoThemeData]. @protected CupertinoThemeData resolveFrom(BuildContext context, { bool nullOk = false }) { - Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); + Color? convertColor(Color? color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); return CupertinoThemeData._rawWithDefaults( brightness, @@ -303,7 +301,7 @@ class CupertinoThemeData with Diagnosticable { _textTheme?.resolveFrom(context, nullOk: nullOk), convertColor(_barBackgroundColor), convertColor(_scaffoldBackgroundColor), - _defaults.resolveFrom(context, _textTheme == null, nullOk: nullOk), + _defaults!.resolveFrom(context, _textTheme == null, nullOk: nullOk), ); } @@ -315,12 +313,12 @@ class CupertinoThemeData with Diagnosticable { /// copying with a different [primaryColor] will also change the copy's implied /// [textTheme]. CupertinoThemeData copyWith({ - Brightness brightness, - Color primaryColor, - Color primaryContrastingColor, - CupertinoTextThemeData textTheme, - Color barBackgroundColor, - Color scaffoldBackgroundColor, + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor, + Color? scaffoldBackgroundColor, }) { return CupertinoThemeData._rawWithDefaults( brightness ?? this.brightness, @@ -342,13 +340,13 @@ class CupertinoThemeData with Diagnosticable { properties.add(createCupertinoColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor)); properties.add(createCupertinoColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor)); properties.add(createCupertinoColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor)); - textTheme.debugFillProperties(properties); + textTheme!.debugFillProperties(properties); } } class _NoDefaultCupertinoThemeData extends CupertinoThemeData { const _NoDefaultCupertinoThemeData( - Brightness brightness, + Brightness? brightness, this.primaryColor, this.primaryContrastingColor, this.textTheme, @@ -365,19 +363,19 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData { ); @override - final Color primaryColor; + final Color? primaryColor; @override - final Color primaryContrastingColor; + final Color? primaryContrastingColor; @override - final CupertinoTextThemeData textTheme; + final CupertinoTextThemeData? textTheme; @override - final Color barBackgroundColor; + final Color? barBackgroundColor; @override - final Color scaffoldBackgroundColor; + final Color? scaffoldBackgroundColor; @override _NoDefaultCupertinoThemeData resolveFrom(BuildContext context, { bool nullOk = false }) { - Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); + Color? convertColor(Color? color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); return _NoDefaultCupertinoThemeData( brightness, @@ -391,12 +389,12 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData { @override CupertinoThemeData copyWith({ - Brightness brightness, - Color primaryColor, - Color primaryContrastingColor, - CupertinoTextThemeData textTheme, - Color barBackgroundColor , - Color scaffoldBackgroundColor, + Brightness? brightness, + Color? primaryColor, + Color? primaryContrastingColor, + CupertinoTextThemeData? textTheme, + Color? barBackgroundColor , + Color? scaffoldBackgroundColor, }) { return _NoDefaultCupertinoThemeData( brightness ?? this.brightness, @@ -420,16 +418,16 @@ class _CupertinoThemeDefaults { this.textThemeDefaults, ); - final Brightness brightness; + final Brightness? brightness; final Color primaryColor; final Color primaryContrastingColor; final Color barBackgroundColor; final Color scaffoldBackgroundColor; final _CupertinoTextThemeDefaults textThemeDefaults; - _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme, { @required bool nullOk }) { + _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme, { required bool nullOk }) { assert(nullOk != null); - Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); + Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk)!; return _CupertinoThemeDefaults( brightness, @@ -437,7 +435,7 @@ class _CupertinoThemeDefaults { convertColor(primaryContrastingColor), convertColor(barBackgroundColor), convertColor(scaffoldBackgroundColor), - resolveTextTheme ? textThemeDefaults?.resolveFrom(context, nullOk: nullOk) : textThemeDefaults, + resolveTextTheme ? textThemeDefaults.resolveFrom(context, nullOk: nullOk) : textThemeDefaults, ); } } @@ -452,14 +450,14 @@ class _CupertinoTextThemeDefaults { final Color labelColor; final Color inactiveGray; - _CupertinoTextThemeDefaults resolveFrom(BuildContext context, { @required bool nullOk }) { + _CupertinoTextThemeDefaults resolveFrom(BuildContext context, { required bool nullOk }) { return _CupertinoTextThemeDefaults( - CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk), - CupertinoDynamicColor.resolve(inactiveGray, context, nullOk: nullOk), + CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk)!, + CupertinoDynamicColor.resolve(inactiveGray, context, nullOk: nullOk)!, ); } - CupertinoTextThemeData createDefaults({ @required Color primaryColor }) { + CupertinoTextThemeData createDefaults({ required Color primaryColor }) { assert(primaryColor != null); return _DefaultCupertinoTextThemeData( primaryColor: primaryColor, @@ -474,9 +472,9 @@ class _CupertinoTextThemeDefaults { // text styles changes. class _DefaultCupertinoTextThemeData extends CupertinoTextThemeData { const _DefaultCupertinoTextThemeData({ - @required this.labelColor, - @required this.inactiveGray, - @required Color primaryColor, + required this.labelColor, + required this.inactiveGray, + required Color primaryColor, }) : assert(labelColor != null), assert(inactiveGray != null), assert(primaryColor != null), diff --git a/packages/flutter/test/cupertino/colors_test.dart b/packages/flutter/test/cupertino/colors_test.dart index 29a319e57e..51357361f7 100644 --- a/packages/flutter/test/cupertino/colors_test.dart +++ b/packages/flutter/test/cupertino/colors_test.dart @@ -167,7 +167,7 @@ void main() { }); test('can resolve null color', () { - expect(CupertinoDynamicColor.resolve(null, null), isNull); + expect(CupertinoDynamicColor.resolve(null, _NullElement.instance), isNull); }); test('withVibrancy constructor creates colors that may depend on vibrancy', () { @@ -589,3 +589,20 @@ void main() { }); }); } + +class _NullElement extends Element { + _NullElement() : super(_NullWidget()); + + static _NullElement instance = _NullElement(); + + @override + bool get debugDoingBuild => throw UnimplementedError(); + + @override + void performRebuild() { } +} + +class _NullWidget extends Widget { + @override + Element createElement() => throw UnimplementedError(); +} \ No newline at end of file