Unverified Commit f5511784 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

migrate material to nullsafety (#67166)

* migrate material to nullsafety

* address review comments

* address review comments

* fix build
parent aaa99f6d
......@@ -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
/// Flutter widgets implementing Material Design.
///
/// To use, import `package:flutter/material.dart`.
......
......@@ -1376,7 +1376,7 @@ class _BackChevron extends StatelessWidget {
@override
Widget build(BuildContext context) {
final TextDirection textDirection = Directionality.of(context)!;
final TextStyle textStyle = DefaultTextStyle.of(context).style!;
final TextStyle textStyle = DefaultTextStyle.of(context).style;
// Replicate the Icon logic here to get a tightly sized icon and add
// custom non-square padding.
......@@ -1982,7 +1982,7 @@ class _NavigationBarComponentsTransition {
opacity: fadeOutBy(0.4),
// Keep the font when transitioning into a non-back-label leading.
child: DefaultTextStyle(
style: bottomLargeTitleTextStyle,
style: bottomLargeTitleTextStyle!,
child: bottomLargeTitle.child,
),
),
......@@ -2219,7 +2219,7 @@ class _NavigationBarComponentsTransition {
child: FadeTransition(
opacity: fadeInFrom(0.3),
child: DefaultTextStyle(
style: topLargeTitleTextStyle,
style: topLargeTitleTextStyle!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: topLargeTitle.child,
......
......@@ -370,7 +370,7 @@ class _SegmentedControlState<T extends Object> extends State<CupertinoSegmentedC
selectedIndex = (widget.groupValue == currentKey) ? index : selectedIndex;
pressedIndex = (_pressedKey == currentKey) ? index : pressedIndex;
final TextStyle textStyle = DefaultTextStyle.of(context).style!.copyWith(
final TextStyle textStyle = DefaultTextStyle.of(context).style.copyWith(
color: getTextColor(index, currentKey),
);
final IconThemeData iconTheme = IconThemeData(
......
......@@ -416,7 +416,7 @@ class _SegmentedControlState<T> extends State<CupertinoSlidingSegmentedControl<T
builder: (BuildContext context, Widget? child) {
final List<Widget> children = <Widget>[];
for (final T currentKey in keys) {
final TextStyle textStyle = DefaultTextStyle.of(context).style!.copyWith(
final TextStyle textStyle = DefaultTextStyle.of(context).style.copyWith(
fontWeight: _highlightTween.evaluate(_highlightControllers[currentKey]!),
);
......
......@@ -703,10 +703,10 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
super.dispose();
}
EditableTextState? get _editableText => editableTextKey.currentState;
EditableTextState get _editableText => editableTextKey.currentState!;
void _requestKeyboard() {
_editableText?.requestKeyboard();
_editableText.requestKeyboard();
}
bool _shouldShowSelectionHandles(SelectionChangedCause? cause) {
......@@ -730,7 +730,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
if (cause == SelectionChangedCause.longPress) {
_editableText?.bringIntoView(selection.base);
_editableText.bringIntoView(selection.base);
}
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
if (willShowSelectionHandles != _showSelectionHandles) {
......
......@@ -961,7 +961,7 @@ class _PackageLicensePageState extends State<_PackageLicensePage> {
);
}
return DefaultTextStyle(
style: theme.textTheme.caption,
style: theme.textTheme.caption!,
child: page,
);
}
......
......@@ -588,7 +588,7 @@ class _AppBarState extends State<AppBar> {
}
title = DefaultTextStyle(
style: centerStyle,
style: centerStyle!,
softWrap: false,
overflow: TextOverflow.ellipsis,
child: title,
......@@ -650,7 +650,7 @@ class _AppBarState extends State<AppBar> {
child: IconTheme.merge(
data: overallIconTheme,
child: DefaultTextStyle(
style: sideStyle,
style: sideStyle!,
child: toolbar,
),
),
......
......@@ -145,7 +145,7 @@ class MaterialBanner extends StatelessWidget {
),
Expanded(
child: DefaultTextStyle(
style: textStyle,
style: textStyle!,
child: content,
),
),
......
......@@ -393,11 +393,11 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
@override
Widget build(BuildContext context) {
final Color? effectiveTextColor = MaterialStateProperty.resolveAs<Color>(widget.textStyle?.color, _states);
final ShapeBorder? effectiveShape = MaterialStateProperty.resolveAs<ShapeBorder>(widget.shape, _states);
final Color? effectiveTextColor = MaterialStateProperty.resolveAs<Color?>(widget.textStyle?.color, _states);
final ShapeBorder? effectiveShape = MaterialStateProperty.resolveAs<ShapeBorder?>(widget.shape, _states);
final Offset densityAdjustment = widget.visualDensity.baseSizeAdjustment;
final BoxConstraints effectiveConstraints = widget.visualDensity.effectiveConstraints(widget.constraints);
final MouseCursor? effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
final MouseCursor? effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(
widget.mouseCursor ?? MaterialStateMouseCursor.clickable,
_states,
);
......
......@@ -261,21 +261,21 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
);
}
final double? resolvedElevation = resolve<double>((ButtonStyle? style) => style?.elevation);
final TextStyle? resolvedTextStyle = resolve<TextStyle>((ButtonStyle? style) => style?.textStyle);
Color? resolvedBackgroundColor = resolve<Color>((ButtonStyle? style) => style?.backgroundColor);
final Color? resolvedForegroundColor = resolve<Color>((ButtonStyle? style) => style?.foregroundColor);
final Color? resolvedShadowColor = resolve<Color>((ButtonStyle? style) => style?.shadowColor);
final EdgeInsetsGeometry? resolvedPadding = resolve<EdgeInsetsGeometry>((ButtonStyle? style) => style?.padding);
final Size? resolvedMinimumSize = resolve<Size>((ButtonStyle? style) => style?.minimumSize);
final BorderSide? resolvedSide = resolve<BorderSide>((ButtonStyle? style) => style?.side);
final OutlinedBorder? resolvedShape = resolve<OutlinedBorder>((ButtonStyle? style) => style?.shape);
final double? resolvedElevation = resolve<double?>((ButtonStyle? style) => style?.elevation);
final TextStyle? resolvedTextStyle = resolve<TextStyle?>((ButtonStyle? style) => style?.textStyle);
Color? resolvedBackgroundColor = resolve<Color?>((ButtonStyle? style) => style?.backgroundColor);
final Color? resolvedForegroundColor = resolve<Color?>((ButtonStyle? style) => style?.foregroundColor);
final Color? resolvedShadowColor = resolve<Color?>((ButtonStyle? style) => style?.shadowColor);
final EdgeInsetsGeometry? resolvedPadding = resolve<EdgeInsetsGeometry?>((ButtonStyle? style) => style?.padding);
final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize);
final BorderSide? resolvedSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side);
final OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape);
final MaterialStateMouseCursor resolvedMouseCursor = _MouseCursor(
(Set<MaterialState> states) => effectiveValue((ButtonStyle? style) => style?.mouseCursor?.resolve(states)),
);
final MaterialStateProperty<Color> overlayColor = MaterialStateProperty.resolveWith<Color>(
final MaterialStateProperty<Color?> overlayColor = MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) => effectiveValue((ButtonStyle? style) => style?.overlayColor?.resolve(states)),
);
......@@ -401,10 +401,10 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
class _MouseCursor extends MaterialStateMouseCursor {
const _MouseCursor(this.resolveCallback);
final MaterialPropertyResolver<MouseCursor> resolveCallback;
final MaterialPropertyResolver<MouseCursor?> resolveCallback;
@override
MouseCursor? resolve(Set<MaterialState> states) => resolveCallback(states);
MouseCursor resolve(Set<MaterialState> states) => resolveCallback(states)!;
@override
String get debugDescription => 'ButtonStyleButton_MouseCursor';
......
......@@ -539,7 +539,7 @@ class ButtonThemeData with Diagnosticable {
/// If [MaterialButton.textColor] is a [MaterialStateProperty<Color>], it will be
/// used as the `disabledTextColor`. It will be resolved in the [MaterialState.disabled] state.
Color getDisabledTextColor(MaterialButton button) {
if (button.textColor is MaterialStateProperty<Color>)
if (button.textColor is MaterialStateProperty<Color?>)
return button.textColor!;
if (button.disabledTextColor != null)
return button.disabledTextColor!;
......
......@@ -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/widgets.dart';
import 'card_theme.dart';
......@@ -104,7 +102,7 @@ class Card extends StatelessWidget {
/// The [elevation] must be null or non-negative. The [borderOnForeground]
/// must not be null.
const Card({
Key key,
Key? key,
this.color,
this.shadowColor,
this.elevation,
......@@ -124,14 +122,14 @@ class Card extends StatelessWidget {
///
/// If this property is null then [CardTheme.color] of [ThemeData.cardTheme]
/// is used. If that's null then [ThemeData.cardColor] is used.
final Color color;
final Color? color;
/// The color to paint the shadow below the card.
///
/// If null then the ambient [CardTheme]'s shadowColor is used.
/// If that's null too, then the overall theme's [ThemeData.shadowColor]
/// (default black) is used.
final Color shadowColor;
final Color? shadowColor;
/// The z-coordinate at which to place this card. This controls the size of
/// the shadow below the card.
......@@ -140,7 +138,7 @@ class Card extends StatelessWidget {
///
/// If this property is null then [CardTheme.elevation] of
/// [ThemeData.cardTheme] is used. If that's null, the default value is 1.0.
final double elevation;
final double? elevation;
/// The shape of the card's [Material].
///
......@@ -149,7 +147,7 @@ class Card extends StatelessWidget {
/// If this property is null then [CardTheme.shape] of [ThemeData.cardTheme]
/// is used. If that's null then the shape will be a [RoundedRectangleBorder]
/// with a circular corner radius of 4.0.
final ShapeBorder shape;
final ShapeBorder? shape;
/// Whether to paint the [shape] border in front of the [child].
///
......@@ -161,7 +159,7 @@ class Card extends StatelessWidget {
///
/// If this property is null then [CardTheme.clipBehavior] of
/// [ThemeData.cardTheme] is used. If that's null then the behavior will be [Clip.none].
final Clip clipBehavior;
final Clip? clipBehavior;
/// The empty space that surrounds the card.
///
......@@ -170,7 +168,7 @@ class Card extends StatelessWidget {
/// If this property is null then [CardTheme.margin] of
/// [ThemeData.cardTheme] is used. If that's null, the default margin is 4.0
/// logical pixels on all sides: `EdgeInsets.all(4.0)`.
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// Whether this widget represents a single semantic container, or if false
/// a collection of individual semantic nodes.
......@@ -188,13 +186,13 @@ class Card extends StatelessWidget {
/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.child}
final Widget child;
final Widget? child;
static const double _defaultElevation = 1.0;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
final CardTheme cardTheme = CardTheme.of(context);
return Semantics(
......
......@@ -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/widgets.dart';
import 'checkbox.dart';
......@@ -259,9 +257,9 @@ class CheckboxListTile extends StatelessWidget {
///
/// The value of [tristate] must not be null.
const CheckboxListTile({
Key key,
@required this.value,
@required this.onChanged,
Key? key,
required this.value,
required this.onChanged,
this.activeColor,
this.checkColor,
this.title,
......@@ -284,7 +282,7 @@ class CheckboxListTile extends StatelessWidget {
super(key: key);
/// Whether this checkbox is checked.
final bool value;
final bool? value;
/// Called when the value of the checkbox should change.
///
......@@ -309,32 +307,32 @@ class CheckboxListTile extends StatelessWidget {
/// title: Text('Throw away your shot'),
/// )
/// ```
final ValueChanged<bool> onChanged;
final ValueChanged<bool?>? onChanged;
/// The color to use when this checkbox is checked.
///
/// Defaults to accent color of the current [Theme].
final Color activeColor;
final Color? activeColor;
/// The color to use for the check icon when this checkbox is checked.
///
/// Defaults to Color(0xFFFFFFFF).
final Color checkColor;
final Color? checkColor;
/// The primary content of the list tile.
///
/// Typically a [Text] widget.
final Widget title;
final Widget? title;
/// Additional content displayed below the title.
///
/// Typically a [Text] widget.
final Widget subtitle;
final Widget? subtitle;
/// A widget to display on the opposite side of the tile from the checkbox.
///
/// Typically an [Icon] widget.
final Widget secondary;
final Widget? secondary;
/// Whether this list tile is intended to display three lines of text.
///
......@@ -345,7 +343,7 @@ class CheckboxListTile extends StatelessWidget {
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
final bool dense;
final bool? dense;
/// Whether to render icons and text in the [activeColor].
///
......@@ -368,7 +366,7 @@ class CheckboxListTile extends StatelessWidget {
/// widgets in [CheckboxListTile].
///
/// When the value is null, the `contentPadding` is `EdgeInsets.symmetric(horizontal: 16.0)`.
final EdgeInsetsGeometry contentPadding;
final EdgeInsetsGeometry? contentPadding;
/// If true the checkbox's [value] can be true, false, or null.
///
......@@ -386,13 +384,13 @@ class CheckboxListTile extends StatelessWidget {
assert(onChanged != null);
switch (value) {
case false:
onChanged(true);
onChanged!(true);
break;
case true:
onChanged(tristate ? null : false);
onChanged!(tristate ? null : false);
break;
default: // case null:
onChanged(false);
case null:
onChanged!(false);
break;
}
}
......@@ -408,7 +406,7 @@ class CheckboxListTile extends StatelessWidget {
autofocus: autofocus,
tristate: tristate,
);
Widget leading, trailing;
Widget? leading, trailing;
switch (controlAffinity) {
case ListTileControlAffinity.leading:
leading = control;
......@@ -422,7 +420,7 @@ class CheckboxListTile extends StatelessWidget {
}
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context).accentColor,
selectedColor: activeColor ?? Theme.of(context)!.accentColor,
child: ListTile(
leading: leading,
title: title,
......
This diff is collapsed.
......@@ -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 lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -47,9 +45,9 @@ class ChipTheme extends InheritedTheme {
///
/// The [data] and [child] arguments must not be null.
const ChipTheme({
Key key,
@required this.data,
@required Widget child,
Key? key,
required this.data,
required Widget child,
}) : assert(child != null),
assert(data != null),
super(key: key, child: child);
......@@ -87,13 +85,13 @@ class ChipTheme extends InheritedTheme {
/// * [ChipThemeData], which describes the actual configuration of a chip
/// theme.
static ChipThemeData of(BuildContext context) {
final ChipTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>();
return inheritedTheme?.data ?? Theme.of(context).chipTheme;
final ChipTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>();
return inheritedTheme?.data ?? Theme.of(context)!.chipTheme;
}
@override
Widget wrap(BuildContext context, Widget child) {
final ChipTheme ancestorTheme = context.findAncestorWidgetOfExactType<ChipTheme>();
final ChipTheme? ancestorTheme = context.findAncestorWidgetOfExactType<ChipTheme>();
return identical(this, ancestorTheme) ? child : ChipTheme(data: data, child: child);
}
......@@ -179,21 +177,21 @@ class ChipThemeData with Diagnosticable {
/// This will rarely be used directly. It is used by [lerp] to
/// create intermediate themes based on two themes.
const ChipThemeData({
@required this.backgroundColor,
required this.backgroundColor,
this.deleteIconColor,
@required this.disabledColor,
@required this.selectedColor,
@required this.secondarySelectedColor,
required this.disabledColor,
required this.selectedColor,
required this.secondarySelectedColor,
this.shadowColor,
this.selectedShadowColor,
this.showCheckmark,
this.checkmarkColor,
this.labelPadding,
@required this.padding,
@required this.shape,
@required this.labelStyle,
@required this.secondaryLabelStyle,
@required this.brightness,
required this.padding,
required this.shape,
required this.labelStyle,
required this.secondaryLabelStyle,
required this.brightness,
this.elevation,
this.pressElevation,
}) : assert(backgroundColor != null),
......@@ -224,10 +222,10 @@ class ChipThemeData with Diagnosticable {
///
/// This is used to generate the default chip theme for a [ThemeData].
factory ChipThemeData.fromDefaults({
Brightness brightness,
Color primaryColor,
@required Color secondaryColor,
@required TextStyle labelStyle,
Brightness? brightness,
Color? primaryColor,
required Color secondaryColor,
required TextStyle labelStyle,
}) {
assert(primaryColor != null || brightness != null,
'One of primaryColor or brightness must be specified');
......@@ -271,7 +269,7 @@ class ChipThemeData with Diagnosticable {
shape: shape,
labelStyle: labelStyle,
secondaryLabelStyle: secondaryLabelStyle,
brightness: brightness,
brightness: brightness!,
);
}
......@@ -285,7 +283,7 @@ class ChipThemeData with Diagnosticable {
/// (slightly transparent white) for dark themes.
///
/// May be set to null, in which case the ambient [IconThemeData.color] is used.
final Color deleteIconColor;
final Color? deleteIconColor;
/// Color to be used for the chip's background indicating that it is disabled.
///
......@@ -317,7 +315,7 @@ class ChipThemeData with Diagnosticable {
/// See also:
///
/// * [selectedShadowColor]
final Color shadowColor;
final Color? shadowColor;
/// Color of the chip's shadow when the elevation is greater than 0 and the
/// chip is selected.
......@@ -327,7 +325,7 @@ class ChipThemeData with Diagnosticable {
/// See also:
///
/// * [shadowColor]
final Color selectedShadowColor;
final Color? selectedShadowColor;
/// Whether or not to show a check mark when [SelectableChipAttributes.selected] is true.
///
......@@ -335,18 +333,18 @@ class ChipThemeData with Diagnosticable {
/// selected without showing the check mark.
///
/// Defaults to true.
final bool showCheckmark;
final bool? showCheckmark;
/// Color of the chip's check mark when a check mark is visible.
///
/// This will override the color set by the platform's brightness setting.
final Color checkmarkColor;
final Color? checkmarkColor;
/// The padding around the [Chip.label] widget.
///
/// By default, this is 4 logical pixels at the beginning and the end of the
/// label, and zero on top and bottom.
final EdgeInsetsGeometry labelPadding;
final EdgeInsetsGeometry? labelPadding;
/// The padding between the contents of the chip and the outside [shape].
///
......@@ -379,32 +377,32 @@ class ChipThemeData with Diagnosticable {
/// The elevation to be applied to the chip.
///
/// If null, the chip defaults to 0.
final double elevation;
final double? elevation;
/// The elevation to be applied to the chip during the press motion.
///
/// If null, the chip defaults to 8.
final double pressElevation;
final double? pressElevation;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
ChipThemeData copyWith({
Color backgroundColor,
Color deleteIconColor,
Color disabledColor,
Color selectedColor,
Color secondarySelectedColor,
Color shadowColor,
Color selectedShadowColor,
Color checkmarkColor,
EdgeInsetsGeometry labelPadding,
EdgeInsetsGeometry padding,
ShapeBorder shape,
TextStyle labelStyle,
TextStyle secondaryLabelStyle,
Brightness brightness,
double elevation,
double pressElevation,
Color? backgroundColor,
Color? deleteIconColor,
Color? disabledColor,
Color? selectedColor,
Color? secondarySelectedColor,
Color? shadowColor,
Color? selectedShadowColor,
Color? checkmarkColor,
EdgeInsetsGeometry? labelPadding,
EdgeInsetsGeometry? padding,
ShapeBorder? shape,
TextStyle? labelStyle,
TextStyle? secondaryLabelStyle,
Brightness? brightness,
double? elevation,
double? pressElevation,
}) {
return ChipThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -431,24 +429,24 @@ class ChipThemeData with Diagnosticable {
/// The arguments must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static ChipThemeData lerp(ChipThemeData a, ChipThemeData b, double t) {
static ChipThemeData? lerp(ChipThemeData? a, ChipThemeData? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
return ChipThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t)!,
deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t),
disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t),
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t),
secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t),
disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t)!,
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t)!,
secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t)!,
shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t),
selectedShadowColor: Color.lerp(a?.selectedShadowColor, b?.selectedShadowColor, t),
checkmarkColor: Color.lerp(a?.checkmarkColor, b?.checkmarkColor, t),
labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t),
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t),
secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t),
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t)!,
shape: ShapeBorder.lerp(a?.shape, b?.shape, t)!,
labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t)!,
secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t)!,
brightness: t < 0.5 ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light,
elevation: lerpDouble(a?.elevation, b?.elevation, t),
pressElevation: lerpDouble(a?.pressElevation, b?.pressElevation, t),
......@@ -511,7 +509,7 @@ class ChipThemeData with Diagnosticable {
final ChipThemeData defaultData = ChipThemeData.fromDefaults(
secondaryColor: defaultTheme.primaryColor,
brightness: defaultTheme.brightness,
labelStyle: defaultTheme.textTheme.bodyText1,
labelStyle: defaultTheme.textTheme.bodyText1!,
);
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor));
properties.add(ColorProperty('deleteIconColor', deleteIconColor, defaultValue: defaultData.deleteIconColor));
......
......@@ -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/widgets.dart';
import 'constants.dart';
......@@ -58,7 +56,7 @@ import 'theme_data.dart';
class CircleAvatar extends StatelessWidget {
/// Creates a circle that represents a user.
const CircleAvatar({
Key key,
Key? key,
this.child,
this.backgroundColor,
this.backgroundImage,
......@@ -75,7 +73,7 @@ class CircleAvatar extends StatelessWidget {
///
/// Typically a [Text] widget. If the [CircleAvatar] is to have an image, use
/// [backgroundImage] instead.
final Widget child;
final Widget? child;
/// The color with which to fill the circle. Changing the background
/// color will cause the avatar to animate to the new color.
......@@ -83,7 +81,7 @@ class CircleAvatar extends StatelessWidget {
/// If a [backgroundColor] is not specified, the theme's
/// [ThemeData.primaryColorLight] is used with dark foreground colors, and
/// [ThemeData.primaryColorDark] with light foreground colors.
final Color backgroundColor;
final Color? backgroundColor;
/// The default text color for text in the circle.
///
......@@ -92,17 +90,17 @@ class CircleAvatar extends StatelessWidget {
///
/// Defaults to [ThemeData.primaryColorLight] for dark background colors, and
/// [ThemeData.primaryColorDark] for light background colors.
final Color foregroundColor;
final Color? foregroundColor;
/// The background image of the circle. Changing the background
/// image will cause the avatar to animate to the new image.
///
/// If the [CircleAvatar] is to have the user's initials, use [child] instead.
final ImageProvider backgroundImage;
final ImageProvider? backgroundImage;
/// An optional error callback for errors emitted when loading
/// [backgroundImage].
final ImageErrorListener onBackgroundImageError;
final ImageErrorListener? onBackgroundImageError;
/// The size of the avatar, expressed as the radius (half the diameter).
///
......@@ -116,7 +114,7 @@ class CircleAvatar extends StatelessWidget {
///
/// Changes to the [radius] are animated (including changing from an explicit
/// [radius] to a [minRadius]/[maxRadius] pair or vice versa).
final double radius;
final double? radius;
/// The minimum size of the avatar, expressed as the radius (half the
/// diameter).
......@@ -132,7 +130,7 @@ class CircleAvatar extends StatelessWidget {
/// However, if the [minRadius] is 40 and the [CircleAvatar] has a parent
/// [SizedBox] whose size changes instantaneously from 20 pixels to 40 pixels,
/// the size will snap to 40 pixels instantly.
final double minRadius;
final double? minRadius;
/// The maximum size of the avatar, expressed as the radius (half the
/// diameter).
......@@ -148,7 +146,7 @@ class CircleAvatar extends StatelessWidget {
/// However, if the [maxRadius] is 40 and the [CircleAvatar] has a parent
/// [SizedBox] whose size changes instantaneously from 20 pixels to 40 pixels,
/// the size will snap to 40 pixels instantly.
final double maxRadius;
final double? maxRadius;
// The default radius if nothing is specified.
static const double _defaultRadius = 20.0;
......@@ -176,11 +174,11 @@ class CircleAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context);
TextStyle textStyle = theme.primaryTextTheme.subtitle1.copyWith(color: foregroundColor);
Color effectiveBackgroundColor = backgroundColor;
final ThemeData theme = Theme.of(context)!;
TextStyle textStyle = theme.primaryTextTheme.subtitle1!.copyWith(color: foregroundColor);
Color? effectiveBackgroundColor = backgroundColor;
if (effectiveBackgroundColor == null) {
switch (ThemeData.estimateBrightnessForColor(textStyle.color)) {
switch (ThemeData.estimateBrightnessForColor(textStyle.color!)) {
case Brightness.dark:
effectiveBackgroundColor = theme.primaryColorLight;
break;
......@@ -189,7 +187,7 @@ class CircleAvatar extends StatelessWidget {
break;
}
} else if (foregroundColor == null) {
switch (ThemeData.estimateBrightnessForColor(backgroundColor)) {
switch (ThemeData.estimateBrightnessForColor(backgroundColor!)) {
case Brightness.dark:
textStyle = textStyle.copyWith(color: theme.primaryColorLight);
break;
......@@ -212,7 +210,7 @@ class CircleAvatar extends StatelessWidget {
color: effectiveBackgroundColor,
image: backgroundImage != null
? DecorationImage(
image: backgroundImage,
image: backgroundImage!,
onError: onBackgroundImageError,
fit: BoxFit.cover,
)
......@@ -225,12 +223,12 @@ class CircleAvatar extends StatelessWidget {
child: MediaQuery(
// Need to ignore the ambient textScaleFactor here so that the
// text doesn't escape the avatar when the textScaleFactor is large.
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 1.0),
child: IconTheme(
data: theme.iconTheme.copyWith(color: textStyle.color),
child: DefaultTextStyle(
style: textStyle,
child: child,
child: child!,
),
),
),
......
......@@ -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';
......@@ -21,19 +19,19 @@ import 'theme_data.dart';
class ColorScheme with Diagnosticable {
/// Create a ColorScheme instance.
const ColorScheme({
@required this.primary,
@required this.primaryVariant,
@required this.secondary,
@required this.secondaryVariant,
@required this.surface,
@required this.background,
@required this.error,
@required this.onPrimary,
@required this.onSecondary,
@required this.onSurface,
@required this.onBackground,
@required this.onError,
@required this.brightness,
required this.primary,
required this.primaryVariant,
required this.secondary,
required this.secondaryVariant,
required this.surface,
required this.background,
required this.error,
required this.onPrimary,
required this.onSecondary,
required this.onSurface,
required this.onBackground,
required this.onError,
required this.brightness,
}) : assert(primary != null),
assert(primaryVariant != null),
assert(secondary != null),
......@@ -175,11 +173,11 @@ class ColorScheme with Diagnosticable {
/// color scheme.
factory ColorScheme.fromSwatch({
MaterialColor primarySwatch = Colors.blue,
Color primaryColorDark,
Color accentColor,
Color cardColor,
Color backgroundColor,
Color errorColor,
Color? primaryColorDark,
Color? accentColor,
Color? cardColor,
Color? backgroundColor,
Color? errorColor,
Brightness brightness = Brightness.light,
}) {
assert(primarySwatch != null);
......@@ -187,17 +185,17 @@ class ColorScheme with Diagnosticable {
final bool isDark = brightness == Brightness.dark;
final bool primaryIsDark = _brightnessFor(primarySwatch) == Brightness.dark;
final Color secondary = accentColor ?? (isDark ? Colors.tealAccent[200] : primarySwatch);
final Color secondary = accentColor ?? (isDark ? Colors.tealAccent[200]! : primarySwatch);
final bool secondaryIsDark = _brightnessFor(secondary) == Brightness.dark;
return ColorScheme(
primary: primarySwatch,
primaryVariant: primaryColorDark ?? (isDark ? Colors.black : primarySwatch[700]),
primaryVariant: primaryColorDark ?? (isDark ? Colors.black : primarySwatch[700]!),
secondary: secondary,
secondaryVariant: isDark ? Colors.tealAccent[700] : primarySwatch[700],
surface: cardColor ?? (isDark ? Colors.grey[800] : Colors.white),
background: backgroundColor ?? (isDark ? Colors.grey[700] : primarySwatch[200]),
error: errorColor ?? Colors.red[700],
secondaryVariant: isDark ? Colors.tealAccent[700]! : primarySwatch[700]!,
surface: cardColor ?? (isDark ? Colors.grey[800]! : Colors.white),
background: backgroundColor ?? (isDark ? Colors.grey[700]! : primarySwatch[200]!),
error: errorColor ?? Colors.red[700]!,
onPrimary: primaryIsDark ? Colors.white : Colors.black,
onSecondary: secondaryIsDark ? Colors.white : Colors.black,
onSurface: isDark ? Colors.white : Colors.black,
......@@ -273,19 +271,19 @@ class ColorScheme with Diagnosticable {
/// Creates a copy of this color scheme with the given fields
/// replaced by the non-null parameter values.
ColorScheme copyWith({
Color primary,
Color primaryVariant,
Color secondary,
Color secondaryVariant,
Color surface,
Color background,
Color error,
Color onPrimary,
Color onSecondary,
Color onSurface,
Color onBackground,
Color onError,
Brightness brightness,
Color? primary,
Color? primaryVariant,
Color? secondary,
Color? secondaryVariant,
Color? surface,
Color? background,
Color? error,
Color? onPrimary,
Color? onSecondary,
Color? onSurface,
Color? onBackground,
Color? onError,
Brightness? brightness,
}) {
return ColorScheme(
primary: primary ?? this.primary,
......@@ -309,18 +307,18 @@ class ColorScheme with Diagnosticable {
/// {@macro dart.ui.shadow.lerp}
static ColorScheme lerp(ColorScheme a, ColorScheme b, double t) {
return ColorScheme(
primary: Color.lerp(a.primary, b.primary, t),
primaryVariant: Color.lerp(a.primaryVariant, b.primaryVariant, t),
secondary: Color.lerp(a.secondary, b.secondary, t),
secondaryVariant: Color.lerp(a.secondaryVariant, b.secondaryVariant, t),
surface: Color.lerp(a.surface, b.surface, t),
background: Color.lerp(a.background, b.background, t),
error: Color.lerp(a.error, b.error, t),
onPrimary: Color.lerp(a.onPrimary, b.onPrimary, t),
onSecondary: Color.lerp(a.onSecondary, b.onSecondary, t),
onSurface: Color.lerp(a.onSurface, b.onSurface, t),
onBackground: Color.lerp(a.onBackground, b.onBackground, t),
onError: Color.lerp(a.onError, b.onError, t),
primary: Color.lerp(a.primary, b.primary, t)!,
primaryVariant: Color.lerp(a.primaryVariant, b.primaryVariant, t)!,
secondary: Color.lerp(a.secondary, b.secondary, t)!,
secondaryVariant: Color.lerp(a.secondaryVariant, b.secondaryVariant, t)!,
surface: Color.lerp(a.surface, b.surface, t)!,
background: Color.lerp(a.background, b.background, t)!,
error: Color.lerp(a.error, b.error, t)!,
onPrimary: Color.lerp(a.onPrimary, b.onPrimary, t)!,
onSecondary: Color.lerp(a.onSecondary, b.onSecondary, t)!,
onSurface: Color.lerp(a.onSurface, b.onSurface, t)!,
onBackground: Color.lerp(a.onBackground, b.onBackground, t)!,
onError: Color.lerp(a.onError, b.onError, t)!,
brightness: t < 0.5 ? a.brightness : b.brightness,
);
}
......
......@@ -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 'data_table.dart';
......@@ -35,7 +33,7 @@ abstract class DataTableSource extends ChangeNotifier {
///
/// Data returned from this method must be consistent for the lifetime of the
/// object. If the row count changes, then a new delegate must be provided.
DataRow getRow(int index);
DataRow? getRow(int index);
/// Called to obtain the number of rows to tell the user are available.
///
......
......@@ -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 lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -50,44 +48,44 @@ class DataTableThemeData with Diagnosticable {
/// {@macro flutter.material.dataTable.dataRowColor}
/// {@macro flutter.material.dataTable.dataRowColorCode}
final MaterialStateProperty<Color> dataRowColor;
final MaterialStateProperty<Color?>? dataRowColor;
/// {@macro flutter.material.dataTable.dataRowHeight}
final double dataRowHeight;
final double? dataRowHeight;
/// {@macro flutter.material.dataTable.dataTextStyle}
final TextStyle dataTextStyle;
final TextStyle? dataTextStyle;
/// {@macro flutter.material.dataTable.headingRowColor}
final MaterialStateProperty<Color> headingRowColor;
final MaterialStateProperty<Color?>? headingRowColor;
/// {@macro flutter.material.dataTable.headingRowHeight}
final double headingRowHeight;
final double? headingRowHeight;
/// {@macro flutter.material.dataTable.headingTextStyle}
final TextStyle headingTextStyle;
final TextStyle? headingTextStyle;
/// {@macro flutter.material.dataTable.horizontalMargin}
final double horizontalMargin;
final double? horizontalMargin;
/// {@macro flutter.material.dataTable.columnSpacing}
final double columnSpacing;
final double? columnSpacing;
/// {@macro flutter.material.dataTable.dividerThickness}
final double dividerThickness;
final double? dividerThickness;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
DataTableThemeData copyWith({
MaterialStateProperty<Color> dataRowColor,
double dataRowHeight,
TextStyle dataTextStyle,
MaterialStateProperty<Color> headingRowColor,
double headingRowHeight,
TextStyle headingTextStyle,
double horizontalMargin,
double columnSpacing,
double dividerThickness,
MaterialStateProperty<Color?>? dataRowColor,
double? dataRowHeight,
TextStyle? dataTextStyle,
MaterialStateProperty<Color?>? headingRowColor,
double? headingRowHeight,
TextStyle? headingTextStyle,
double? horizontalMargin,
double? columnSpacing,
double? dividerThickness,
}) {
return DataTableThemeData(
dataRowColor: dataRowColor ?? this.dataRowColor,
......@@ -110,10 +108,10 @@ class DataTableThemeData with Diagnosticable {
static DataTableThemeData lerp(DataTableThemeData a, DataTableThemeData b, double t) {
assert(t != null);
return DataTableThemeData(
dataRowColor: _lerpProperties(a.dataRowColor, b.dataRowColor, t, Color.lerp),
dataRowColor: _lerpProperties<Color?>(a.dataRowColor, b.dataRowColor, t, Color.lerp),
dataRowHeight: lerpDouble(a.dataRowHeight, b.dataRowHeight, t),
dataTextStyle: TextStyle.lerp(a.dataTextStyle, b.dataTextStyle, t),
headingRowColor: _lerpProperties(a.headingRowColor, b.headingRowColor, t, Color.lerp),
headingRowColor: _lerpProperties<Color?>(a.headingRowColor, b.headingRowColor, t, Color.lerp),
headingRowHeight: lerpDouble(a.headingRowHeight, b.headingRowHeight, t),
headingTextStyle: TextStyle.lerp(a.headingTextStyle, b.headingTextStyle, t),
horizontalMargin: lerpDouble(a.horizontalMargin, b.horizontalMargin, t),
......@@ -158,10 +156,10 @@ class DataTableThemeData with Diagnosticable {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<MaterialStateProperty<Color>>('dataRowColor', dataRowColor, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('dataRowColor', dataRowColor, defaultValue: null));
properties.add(DoubleProperty('dataRowHeight', dataRowHeight, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('dataTextStyle', dataTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Color>>('headingRowColor', headingRowColor, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('headingRowColor', headingRowColor, defaultValue: null));
properties.add(DoubleProperty('headingRowHeight', headingRowHeight, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('headingTextStyle', headingTextStyle, defaultValue: null));
properties.add(DoubleProperty('horizontalMargin', horizontalMargin, defaultValue: null));
......@@ -169,7 +167,7 @@ class DataTableThemeData with Diagnosticable {
properties.add(DoubleProperty('dividerThickness', dividerThickness, defaultValue: null));
}
static MaterialStateProperty<T> _lerpProperties<T>(MaterialStateProperty<T> a, MaterialStateProperty<T> b, double t, T Function(T, T, double) lerpFunction ) {
static MaterialStateProperty<T>? _lerpProperties<T>(MaterialStateProperty<T>? a, MaterialStateProperty<T>? b, double t, T Function(T?, T?, double) lerpFunction ) {
// Avoid creating a _LerpProperties object for a common case.
if (a == null && b == null)
return null;
......@@ -180,15 +178,15 @@ class DataTableThemeData with Diagnosticable {
class _LerpProperties<T> implements MaterialStateProperty<T> {
const _LerpProperties(this.a, this.b, this.t, this.lerpFunction);
final MaterialStateProperty<T> a;
final MaterialStateProperty<T> b;
final MaterialStateProperty<T>? a;
final MaterialStateProperty<T>? b;
final double t;
final T Function(T, T, double) lerpFunction;
final T Function(T?, T?, double) lerpFunction;
@override
T resolve(Set<MaterialState> states) {
final T resolvedA = a?.resolve(states);
final T resolvedB = b?.resolve(states);
final T? resolvedA = a?.resolve(states);
final T? resolvedB = b?.resolve(states);
return lerpFunction(resolvedA, resolvedB, t);
}
}
......@@ -212,9 +210,9 @@ class DataTableTheme extends InheritedWidget {
///
/// The [data] must not be null.
const DataTableTheme({
Key key,
@required this.data,
Widget child,
Key? key,
required this.data,
required Widget child,
}) : assert(data != null), super(key: key, child: child);
/// The properties used for all descendant [DataTable] widgets.
......@@ -231,8 +229,8 @@ class DataTableTheme extends InheritedWidget {
/// DataTableThemeData theme = DataTableTheme.of(context);
/// ```
static DataTableThemeData of(BuildContext context) {
final DataTableTheme dataTableTheme = context.dependOnInheritedWidgetOfExactType<DataTableTheme>();
return dataTableTheme?.data ?? Theme.of(context).dataTableTheme;
final DataTableTheme? dataTableTheme = context.dependOnInheritedWidgetOfExactType<DataTableTheme>();
return dataTableTheme?.data ?? Theme.of(context)!.dataTableTheme;
}
@override
......
......@@ -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 lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -44,34 +42,34 @@ class DialogTheme with Diagnosticable {
///
/// If null, [ThemeData.dialogBackgroundColor] is used, if that's null,
/// defaults to [Colors.white].
final Color backgroundColor;
final Color? backgroundColor;
/// Default value for [Dialog.elevation].
///
/// If null, the [Dialog] elevation defaults to `24.0`.
final double elevation;
final double? elevation;
/// Default value for [Dialog.shape].
final ShapeBorder shape;
final ShapeBorder? shape;
/// Used to configure the [DefaultTextStyle] for the [AlertDialog.title] widget.
///
/// If null, defaults to [TextTheme.headline6] of [ThemeData.textTheme].
final TextStyle titleTextStyle;
final TextStyle? titleTextStyle;
/// Used to configure the [DefaultTextStyle] for the [AlertDialog.content] widget.
///
/// If null, defaults to [TextTheme.subtitle1] of [ThemeData.textTheme].
final TextStyle contentTextStyle;
final TextStyle? contentTextStyle;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
DialogTheme copyWith({
Color backgroundColor,
double elevation,
ShapeBorder shape,
TextStyle titleTextStyle,
TextStyle contentTextStyle,
Color? backgroundColor,
double? elevation,
ShapeBorder? shape,
TextStyle? titleTextStyle,
TextStyle? contentTextStyle,
}) {
return DialogTheme(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -84,7 +82,7 @@ class DialogTheme with Diagnosticable {
/// The data from the closest [DialogTheme] instance given the build context.
static DialogTheme of(BuildContext context) {
return Theme.of(context).dialogTheme;
return Theme.of(context)!.dialogTheme;
}
/// Linearly interpolate between two dialog themes.
......@@ -92,7 +90,7 @@ class DialogTheme with Diagnosticable {
/// The arguments must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static DialogTheme lerp(DialogTheme a, DialogTheme b, double t) {
static DialogTheme lerp(DialogTheme? a, DialogTheme? b, double t) {
assert(t != null);
return DialogTheme(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
......
......@@ -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/widgets.dart';
import 'package:flutter/painting.dart';
......@@ -92,7 +90,7 @@ class Divider extends StatelessWidget {
/// The [height], [thickness], [indent], and [endIndent] must be null or
/// non-negative.
const Divider({
Key key,
Key? key,
this.height,
this.thickness,
this.indent,
......@@ -112,7 +110,7 @@ class Divider extends StatelessWidget {
///
/// If this is null, then the [DividerThemeData.space] is used. If that is
/// also null, then this defaults to 16.0.
final double height;
final double? height;
/// The thickness of the line drawn within the divider.
///
......@@ -121,19 +119,19 @@ class Divider extends StatelessWidget {
///
/// If this is null, then the [DividerThemeData.thickness] is used. If
/// that is also null, then this defaults to 0.0.
final double thickness;
final double? thickness;
/// The amount of empty space to the leading edge of the divider.
///
/// If this is null, then the [DividerThemeData.indent] is used. If that is
/// also null, then this defaults to 0.0.
final double indent;
final double? indent;
/// The amount of empty space to the trailing edge of the divider.
///
/// If this is null, then the [DividerThemeData.endIndent] is used. If that is
/// also null, then this defaults to 0.0.
final double endIndent;
final double? endIndent;
/// The color to use when painting the line.
///
......@@ -148,7 +146,7 @@ class Divider extends StatelessWidget {
/// )
/// ```
/// {@end-tool}
final Color color;
final Color? color;
/// Computes the [BorderSide] that represents a divider.
///
......@@ -179,9 +177,9 @@ class Divider extends StatelessWidget {
/// )
/// ```
/// {@end-tool}
static BorderSide createBorderSide(BuildContext context, { Color color, double width }) {
final Color effectiveColor = color
?? (context != null ? (DividerTheme.of(context).color ?? Theme.of(context).dividerColor) : null);
static BorderSide createBorderSide(BuildContext? context, { Color? color, double? width }) {
final Color? effectiveColor = color
?? (context != null ? (DividerTheme.of(context).color ?? Theme.of(context)!.dividerColor) : null);
final double effectiveWidth = width
?? (context != null ? DividerTheme.of(context).thickness : null)
?? 0.0;
......@@ -243,7 +241,7 @@ class VerticalDivider extends StatelessWidget {
/// The [width], [thickness], [indent], and [endIndent] must be null or
/// non-negative.
const VerticalDivider({
Key key,
Key? key,
this.width,
this.thickness,
this.indent,
......@@ -262,7 +260,7 @@ class VerticalDivider extends StatelessWidget {
///
/// If this is null, then the [DividerThemeData.space] is used. If that is
/// also null, then this defaults to 16.0.
final double width;
final double? width;
/// The thickness of the line drawn within the divider.
///
......@@ -271,19 +269,19 @@ class VerticalDivider extends StatelessWidget {
///
/// If this is null, then the [DividerThemeData.thickness] is used which
/// defaults to 0.0.
final double thickness;
final double? thickness;
/// The amount of empty space on top of the divider.
///
/// If this is null, then the [DividerThemeData.indent] is used. If that is
/// also null, then this defaults to 0.0.
final double indent;
final double? indent;
/// The amount of empty space under the divider.
///
/// If this is null, then the [DividerThemeData.endIndent] is used. If that is
/// also null, then this defaults to 0.0.
final double endIndent;
final double? endIndent;
/// The color to use when painting the line.
///
......@@ -298,7 +296,7 @@ class VerticalDivider extends StatelessWidget {
/// )
/// ```
/// {@end-tool}
final Color color;
final Color? color;
@override
Widget build(BuildContext context) {
......
......@@ -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 lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -43,33 +41,33 @@ class DividerThemeData with Diagnosticable {
/// The color of [Divider]s and [VerticalDivider]s, also
/// used between [ListTile]s, between rows in [DataTable]s, and so forth.
final Color color;
final Color? color;
/// The [Divider]'s width or the [VerticalDivider]'s height.
///
/// This represents the amount of horizontal or vertical space the divider
/// takes up.
final double space;
final double? space;
/// The thickness of the line drawn within the divider.
final double thickness;
final double? thickness;
/// The amount of empty space at the leading edge of [Divider] or top edge of
/// [VerticalDivider].
final double indent;
final double? indent;
/// The amount of empty space at the trailing edge of [Divider] or bottom edge
/// of [VerticalDivider].
final double endIndent;
final double? endIndent;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
DividerThemeData copyWith({
Color color,
double space,
double thickness,
double indent,
double endIndent,
Color? color,
double? space,
double? thickness,
double? indent,
double? endIndent,
}) {
return DividerThemeData(
color: color ?? this.color,
......@@ -85,7 +83,7 @@ class DividerThemeData with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static DividerThemeData lerp(DividerThemeData a, DividerThemeData b, double t) {
static DividerThemeData lerp(DividerThemeData? a, DividerThemeData? b, double t) {
assert(t != null);
return DividerThemeData(
color: Color.lerp(a?.color, b?.color, t),
......@@ -140,9 +138,9 @@ class DividerTheme extends InheritedTheme {
/// [Divider]s, [VerticalDivider]s, dividers between [ListTile]s, and dividers
/// between rows in [DataTable]s in its widget subtree.
const DividerTheme({
Key key,
@required this.data,
Widget child,
Key? key,
required this.data,
required Widget child,
}) : assert(data != null),
super(key: key, child: child);
......@@ -162,13 +160,13 @@ class DividerTheme extends InheritedTheme {
/// DividerThemeData theme = DividerTheme.of(context);
/// ```
static DividerThemeData of(BuildContext context) {
final DividerTheme dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>();
return dividerTheme?.data ?? Theme.of(context).dividerTheme;
final DividerTheme? dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>();
return dividerTheme?.data ?? Theme.of(context)!.dividerTheme;
}
@override
Widget wrap(BuildContext context, Widget child) {
final DividerTheme ancestorTheme = context.findAncestorWidgetOfExactType<DividerTheme>();
final DividerTheme? ancestorTheme = context.findAncestorWidgetOfExactType<DividerTheme>();
return identical(this, ancestorTheme) ? child : DividerTheme(data: data, child: child);
}
......
......@@ -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 'package:flutter/gestures.dart' show DragStartBehavior;
......@@ -141,7 +139,7 @@ class Drawer extends StatelessWidget {
///
/// The [elevation] must be non-negative.
const Drawer({
Key key,
Key? key,
this.elevation = 16.0,
this.child,
this.semanticLabel,
......@@ -161,7 +159,7 @@ class Drawer extends StatelessWidget {
/// Typically a [SliverList].
///
/// {@macro flutter.widgets.child}
final Widget child;
final Widget? child;
/// The semantic label of the dialog used by accessibility frameworks to
/// announce screen transitions when the drawer is opened and closed.
......@@ -173,13 +171,13 @@ class Drawer extends StatelessWidget {
///
/// * [SemanticsConfiguration.namesRoute], for a description of how this
/// value is used.
final String semanticLabel;
final String? semanticLabel;
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
String label = semanticLabel;
switch (Theme.of(context).platform) {
String? label = semanticLabel;
switch (Theme.of(context)!.platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
label = semanticLabel;
......@@ -231,9 +229,9 @@ class DrawerController extends StatefulWidget {
///
/// The [child] argument must not be null and is typically a [Drawer].
const DrawerController({
GlobalKey key,
@required this.child,
@required this.alignment,
GlobalKey? key,
required this.child,
required this.alignment,
this.drawerCallback,
this.dragStartBehavior = DragStartBehavior.start,
this.scrimColor,
......@@ -256,7 +254,7 @@ class DrawerController extends StatefulWidget {
final DrawerAlignment alignment;
/// Optional callback that is called when a [Drawer] is opened or closed.
final DrawerCallback drawerCallback;
final DrawerCallback? drawerCallback;
/// {@template flutter.material.drawer.dragStartBehavior}
/// Determines the way that drag start behavior is handled.
......@@ -283,7 +281,7 @@ class DrawerController extends StatefulWidget {
/// The color to use for the scrim that obscures primary content while a drawer is open.
///
/// By default, the color used is [Colors.black54]
final Color scrimColor;
final Color? scrimColor;
/// Determines if the [Drawer] can be opened with a drag gesture.
///
......@@ -299,7 +297,7 @@ class DrawerController extends StatefulWidget {
/// example, if [alignment] is set to [DrawerAlignment.start] and
/// `TextDirection.of(context)` is set to [TextDirection.ltr],
/// 20.0 will be added to `MediaQuery.of(context).padding.left`.
final double edgeDragWidth;
final double? edgeDragWidth;
@override
DrawerControllerState createState() => DrawerControllerState();
......@@ -338,15 +336,15 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
});
}
LocalHistoryEntry _historyEntry;
LocalHistoryEntry? _historyEntry;
final FocusScopeNode _focusScopeNode = FocusScopeNode();
void _ensureHistoryEntry() {
if (_historyEntry == null) {
final ModalRoute<dynamic> route = ModalRoute.of(context);
final ModalRoute<dynamic>? route = ModalRoute.of(context);
if (route != null) {
_historyEntry = LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved);
route.addLocalHistoryEntry(_historyEntry);
route.addLocalHistoryEntry(_historyEntry!);
FocusScope.of(context).setFirstFocus(_focusScopeNode);
}
}
......@@ -373,7 +371,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
close();
}
AnimationController _controller;
late AnimationController _controller;
void _handleDragDown(DragDownDetails details) {
_controller.stop();
......@@ -393,7 +391,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
final GlobalKey _drawerKey = GlobalKey();
double get _width {
final RenderBox box = _drawerKey.currentContext?.findRenderObject() as RenderBox;
final RenderBox? box = _drawerKey.currentContext?.findRenderObject() as RenderBox?;
if (box != null)
return box.size.width;
return _kWidth; // drawer not being shown currently
......@@ -402,7 +400,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
bool _previouslyOpened = false;
void _move(DragUpdateDetails details) {
double delta = details.primaryDelta / _width;
double delta = details.primaryDelta! / _width;
switch (widget.alignment) {
case DrawerAlignment.start:
break;
......@@ -410,7 +408,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
delta = -delta;
break;
}
switch (Directionality.of(context)) {
switch (Directionality.of(context)!) {
case TextDirection.rtl:
_controller.value -= delta;
break;
......@@ -421,7 +419,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
final bool opened = _controller.value > 0.5;
if (opened != _previouslyOpened && widget.drawerCallback != null)
widget.drawerCallback(opened);
widget.drawerCallback!(opened);
_previouslyOpened = opened;
}
......@@ -437,16 +435,16 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
visualVelocity = -visualVelocity;
break;
}
switch (Directionality.of(context)) {
switch (Directionality.of(context)!) {
case TextDirection.rtl:
_controller.fling(velocity: -visualVelocity);
if (widget.drawerCallback != null)
widget.drawerCallback(visualVelocity < 0.0);
widget.drawerCallback!(visualVelocity < 0.0);
break;
case TextDirection.ltr:
_controller.fling(velocity: visualVelocity);
if (widget.drawerCallback != null)
widget.drawerCallback(visualVelocity > 0.0);
widget.drawerCallback!(visualVelocity > 0.0);
break;
}
} else if (_controller.value < 0.5) {
......@@ -462,17 +460,17 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
void open() {
_controller.fling(velocity: 1.0);
if (widget.drawerCallback != null)
widget.drawerCallback(true);
widget.drawerCallback!(true);
}
/// Starts an animation to close the drawer.
void close() {
_controller.fling(velocity: -1.0);
if (widget.drawerCallback != null)
widget.drawerCallback(false);
widget.drawerCallback!(false);
}
ColorTween _scrimColorTween;
late ColorTween _scrimColorTween;
final GlobalKey _gestureDetectorKey = GlobalKey();
ColorTween _buildScrimColorTween() {
......@@ -487,7 +485,6 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
case DrawerAlignment.end:
return AlignmentDirectional.centerEnd;
}
return null;
}
AlignmentDirectional get _drawerInnerAlignment {
......@@ -498,17 +495,16 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
case DrawerAlignment.end:
return AlignmentDirectional.centerStart;
}
return null;
}
Widget _buildDrawer(BuildContext context) {
final bool drawerIsStart = widget.alignment == DrawerAlignment.start;
final EdgeInsets padding = MediaQuery.of(context).padding;
final TextDirection textDirection = Directionality.of(context);
final EdgeInsets padding = MediaQuery.of(context)!.padding;
final TextDirection? textDirection = Directionality.of(context);
double dragAreaWidth = widget.edgeDragWidth;
double? dragAreaWidth = widget.edgeDragWidth;
if (widget.edgeDragWidth == null) {
switch (textDirection) {
switch (textDirection!) {
case TextDirection.ltr:
dragAreaWidth = _kEdgeDragWidth +
(drawerIsStart ? padding.left : padding.right);
......@@ -539,7 +535,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
}
} else {
bool platformHasBackButton;
switch (Theme.of(context).platform) {
switch (Theme.of(context)!.platform) {
case TargetPlatform.android:
platformHasBackButton = true;
break;
......
......@@ -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/widgets.dart';
import 'debug.dart';
......@@ -31,13 +29,13 @@ class DrawerHeader extends StatelessWidget {
///
/// Requires one of its ancestors to be a [Material] widget.
const DrawerHeader({
Key key,
Key? key,
this.decoration,
this.margin = const EdgeInsets.only(bottom: 8.0),
this.padding = const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0),
this.duration = const Duration(milliseconds: 250),
this.curve = Curves.fastOutSlowIn,
@required this.child,
required this.child,
}) : super(key: key);
/// Decoration for the main drawer header [Container]; useful for applying
......@@ -46,7 +44,7 @@ class DrawerHeader extends StatelessWidget {
/// This decoration will extend under the system status bar.
///
/// If this is changed, it will be animated according to [duration] and [curve].
final Decoration decoration;
final Decoration? decoration;
/// The padding by which to inset [child].
///
......@@ -57,7 +55,7 @@ class DrawerHeader extends StatelessWidget {
final EdgeInsetsGeometry padding;
/// The margin around the drawer header.
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// The duration for animations of the [decoration].
final Duration duration;
......@@ -71,14 +69,14 @@ class DrawerHeader extends StatelessWidget {
/// precisely, consider using an [Align] or [Center] widget.
///
/// {@macro flutter.widgets.child}
final Widget child;
final Widget? child;
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context);
final double statusBarHeight = MediaQuery.of(context).padding.top;
final ThemeData? theme = Theme.of(context);
final double statusBarHeight = MediaQuery.of(context)!.padding.top;
return Container(
height: statusBarHeight + _kDrawerHeaderHeight,
margin: margin,
......@@ -93,11 +91,11 @@ class DrawerHeader extends StatelessWidget {
duration: duration,
curve: curve,
child: child == null ? null : DefaultTextStyle(
style: theme.textTheme.bodyText1,
style: theme!.textTheme.bodyText1!,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: child,
child: child!,
),
),
),
......
......@@ -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:math' as math;
import 'dart:ui' show lerpDouble;
......@@ -57,14 +55,14 @@ class ElevatedButton extends ButtonStyleButton {
///
/// The [autofocus] and [clipBehavior] arguments must not be null.
const ElevatedButton({
Key key,
@required VoidCallback onPressed,
VoidCallback onLongPress,
ButtonStyle style,
FocusNode focusNode,
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
ButtonStyle? style,
FocusNode? focusNode,
bool autofocus = false,
Clip clipBehavior = Clip.none,
@required Widget child,
required Widget? child,
}) : super(
key: key,
onPressed: onPressed,
......@@ -85,14 +83,14 @@ class ElevatedButton extends ButtonStyleButton {
/// The [icon] and [label] arguments must not be null.
factory ElevatedButton.icon({
Key key,
@required VoidCallback onPressed,
required VoidCallback onPressed,
VoidCallback onLongPress,
ButtonStyle style,
FocusNode focusNode,
bool autofocus,
Clip clipBehavior,
@required Widget icon,
@required Widget label,
required Widget icon,
required Widget label,
}) = _ElevatedButtonWithIcon;
/// A static convenience method that constructs an elevated button
......@@ -133,41 +131,41 @@ class ElevatedButton extends ButtonStyleButton {
/// )
/// ```
static ButtonStyle styleFrom({
Color primary,
Color onPrimary,
Color onSurface,
Color shadowColor,
double elevation,
TextStyle textStyle,
EdgeInsetsGeometry padding,
Size minimumSize,
BorderSide side,
OutlinedBorder shape,
MouseCursor enabledMouseCursor,
MouseCursor disabledMouseCursor,
VisualDensity visualDensity,
MaterialTapTargetSize tapTargetSize,
Duration animationDuration,
bool enableFeedback,
Color? primary,
Color? onPrimary,
Color? onSurface,
Color? shadowColor,
double? elevation,
TextStyle? textStyle,
EdgeInsetsGeometry? padding,
Size? minimumSize,
BorderSide? side,
OutlinedBorder? shape,
MouseCursor? enabledMouseCursor,
MouseCursor? disabledMouseCursor,
VisualDensity? visualDensity,
MaterialTapTargetSize? tapTargetSize,
Duration? animationDuration,
bool? enableFeedback,
}) {
final MaterialStateProperty<Color> backgroundColor = (onSurface == null && primary == null)
final MaterialStateProperty<Color?>? backgroundColor = (onSurface == null && primary == null)
? null
: _ElevatedButtonDefaultBackground(primary, onSurface);
final MaterialStateProperty<Color> foregroundColor = (onSurface == null && onPrimary == null)
final MaterialStateProperty<Color?>? foregroundColor = (onSurface == null && onPrimary == null)
? null
: _ElevatedButtonDefaultForeground(onPrimary, onSurface);
final MaterialStateProperty<Color> overlayColor = (onPrimary == null)
final MaterialStateProperty<Color?>? overlayColor = (onPrimary == null)
? null
: _ElevatedButtonDefaultOverlay(onPrimary);
final MaterialStateProperty<double> elevationValue = (elevation == null)
final MaterialStateProperty<double>? elevationValue = (elevation == null)
? null
: _ElevatedButtonDefaultElevation(elevation);
final MaterialStateProperty<MouseCursor> mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
final MaterialStateProperty<MouseCursor?>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
? null
: _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
return ButtonStyle(
textStyle: MaterialStateProperty.all<TextStyle>(textStyle),
textStyle: MaterialStateProperty.all<TextStyle?>(textStyle),
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
overlayColor: overlayColor,
......@@ -250,7 +248,7 @@ class ElevatedButton extends ButtonStyleButton {
/// * `3 < textScaleFactor` - horizontal(4)
@override
ButtonStyle defaultStyleOf(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
final ColorScheme colorScheme = theme.colorScheme;
final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding(
......@@ -283,20 +281,20 @@ class ElevatedButton extends ButtonStyleButton {
/// Returns the [ElevatedButtonThemeData.style] of the closest
/// [ElevatedButtonTheme] ancestor.
@override
ButtonStyle themeStyleOf(BuildContext context) {
return ElevatedButtonTheme.of(context)?.style;
ButtonStyle? themeStyleOf(BuildContext context) {
return ElevatedButtonTheme.of(context).style;
}
}
@immutable
class _ElevatedButtonDefaultBackground extends MaterialStateProperty<Color> with Diagnosticable {
class _ElevatedButtonDefaultBackground extends MaterialStateProperty<Color?> with Diagnosticable {
_ElevatedButtonDefaultBackground(this.primary, this.onSurface);
final Color primary;
final Color onSurface;
final Color? primary;
final Color? onSurface;
@override
Color resolve(Set<MaterialState> states) {
Color? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled))
return onSurface?.withOpacity(0.12);
return primary;
......@@ -304,14 +302,14 @@ class _ElevatedButtonDefaultBackground extends MaterialStateProperty<Color> with
}
@immutable
class _ElevatedButtonDefaultForeground extends MaterialStateProperty<Color> with Diagnosticable {
class _ElevatedButtonDefaultForeground extends MaterialStateProperty<Color?> with Diagnosticable {
_ElevatedButtonDefaultForeground(this.onPrimary, this.onSurface);
final Color onPrimary;
final Color onSurface;
final Color? onPrimary;
final Color? onSurface;
@override
Color resolve(Set<MaterialState> states) {
Color? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled))
return onSurface?.withOpacity(0.38);
return onPrimary;
......@@ -319,17 +317,17 @@ class _ElevatedButtonDefaultForeground extends MaterialStateProperty<Color> with
}
@immutable
class _ElevatedButtonDefaultOverlay extends MaterialStateProperty<Color> with Diagnosticable {
class _ElevatedButtonDefaultOverlay extends MaterialStateProperty<Color?> with Diagnosticable {
_ElevatedButtonDefaultOverlay(this.onPrimary);
final Color onPrimary;
@override
Color resolve(Set<MaterialState> states) {
Color? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered))
return onPrimary?.withOpacity(0.08);
return onPrimary.withOpacity(0.08);
if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed))
return onPrimary?.withOpacity(0.24);
return onPrimary.withOpacity(0.24);
return null;
}
}
......@@ -355,14 +353,14 @@ class _ElevatedButtonDefaultElevation extends MaterialStateProperty<double> with
}
@immutable
class _ElevatedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor> with Diagnosticable {
class _ElevatedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
_ElevatedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
final MouseCursor enabledCursor;
final MouseCursor disabledCursor;
final MouseCursor? enabledCursor;
final MouseCursor? disabledCursor;
@override
MouseCursor resolve(Set<MaterialState> states) {
MouseCursor? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled))
return disabledCursor;
return enabledCursor;
......@@ -371,15 +369,15 @@ class _ElevatedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCurso
class _ElevatedButtonWithIcon extends ElevatedButton {
_ElevatedButtonWithIcon({
Key key,
@required VoidCallback onPressed,
VoidCallback onLongPress,
ButtonStyle style,
FocusNode focusNode,
bool autofocus,
Clip clipBehavior,
@required Widget icon,
@required Widget label,
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
ButtonStyle? style,
FocusNode? focusNode,
bool? autofocus,
Clip? clipBehavior,
required Widget icon,
required Widget label,
}) : assert(icon != null),
assert(label != null),
super(
......@@ -408,7 +406,7 @@ class _ElevatedButtonWithIcon extends ElevatedButton {
}
class _ElevatedButtonWithIconChild extends StatelessWidget {
const _ElevatedButtonWithIconChild({ Key key, this.label, this.icon }) : super(key: key);
const _ElevatedButtonWithIconChild({ Key? key, required this.label, required this.icon }) : super(key: key);
final Widget label;
final Widget icon;
......@@ -416,7 +414,7 @@ class _ElevatedButtonWithIconChild extends StatelessWidget {
@override
Widget build(BuildContext context) {
final double scale = MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1;
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1));
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[icon, SizedBox(width: gap), label],
......
......@@ -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';
......@@ -44,10 +42,10 @@ class ElevatedButtonThemeData with Diagnosticable {
/// [ElevatedButton.defaultStyleOf].
///
/// If [style] is null, then this theme doesn't override anything.
final ButtonStyle style;
final ButtonStyle? style;
/// Linearly interpolate between two elevated button themes.
static ElevatedButtonThemeData lerp(ElevatedButtonThemeData a, ElevatedButtonThemeData b, double t) {
static ElevatedButtonThemeData? lerp(ElevatedButtonThemeData? a, ElevatedButtonThemeData? b, double t) {
assert (t != null);
if (a == null && b == null)
return null;
......@@ -93,9 +91,9 @@ class ElevatedButtonTheme extends InheritedTheme {
///
/// The [data] parameter must not be null.
const ElevatedButtonTheme({
Key key,
@required this.data,
Widget child,
Key? key,
required this.data,
required Widget child,
}) : assert(data != null), super(key: key, child: child);
/// The configuration of this theme.
......@@ -112,13 +110,13 @@ class ElevatedButtonTheme extends InheritedTheme {
/// ElevatedButtonTheme theme = ElevatedButtonTheme.of(context);
/// ```
static ElevatedButtonThemeData of(BuildContext context) {
final ElevatedButtonTheme buttonTheme = context.dependOnInheritedWidgetOfExactType<ElevatedButtonTheme>();
return buttonTheme?.data ?? Theme.of(context).elevatedButtonTheme;
final ElevatedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<ElevatedButtonTheme>();
return buttonTheme?.data ?? Theme.of(context)!.elevatedButtonTheme;
}
@override
Widget wrap(BuildContext context, Widget child) {
final ElevatedButtonTheme ancestorTheme = context.findAncestorWidgetOfExactType<ElevatedButtonTheme>();
final ElevatedButtonTheme? ancestorTheme = context.findAncestorWidgetOfExactType<ElevatedButtonTheme>();
return identical(this, ancestorTheme) ? child : ElevatedButtonTheme(data: data, child: child);
}
......
......@@ -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:math' as math;
import 'package:flutter/widgets.dart';
......@@ -33,10 +31,10 @@ class ExpandIcon extends StatefulWidget {
/// Creates an [ExpandIcon] with the given padding, and a callback that is
/// triggered when the icon is pressed.
const ExpandIcon({
Key key,
Key? key,
this.isExpanded = false,
this.size = 24.0,
@required this.onPressed,
required this.onPressed,
this.padding = const EdgeInsets.all(8.0),
this.color,
this.disabledColor,
......@@ -61,7 +59,7 @@ class ExpandIcon extends StatefulWidget {
/// between expanded and collapsed. The value passed to the current state.
///
/// If this is set to null, the button will be disabled.
final ValueChanged<bool> onPressed;
final ValueChanged<bool>? onPressed;
/// The padding around the icon. The entire padded icon will react to input
/// gestures.
......@@ -77,7 +75,7 @@ class ExpandIcon extends StatefulWidget {
/// [Colors.white60] when it is [Brightness.dark]. This adheres to the
/// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color)
/// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application)
final Color color;
final Color? color;
/// The color of the icon when it is disabled,
/// i.e. if [onPressed] is null.
......@@ -87,7 +85,7 @@ class ExpandIcon extends StatefulWidget {
/// [Colors.white38] when it is [Brightness.dark]. This adheres to the
/// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color)
/// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application)
final Color disabledColor;
final Color? disabledColor;
/// The color of the icon when the icon is expanded.
///
......@@ -96,15 +94,15 @@ class ExpandIcon extends StatefulWidget {
/// [Colors.white] when it is [Brightness.dark]. This adheres to the
/// Material Design specifications for [icons](https://material.io/design/iconography/system-icons.html#color)
/// and for [dark theme](https://material.io/design/color/dark-theme.html#ui-application)
final Color expandedColor;
final Color? expandedColor;
@override
_ExpandIconState createState() => _ExpandIconState();
}
class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _iconTurns;
late AnimationController _controller;
late Animation<double> _iconTurns;
static final Animatable<double> _iconTurnTween = Tween<double>(begin: 0.0, end: 0.5)
.chain(CurveTween(curve: Curves.fastOutSlowIn));
......@@ -140,7 +138,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
void _handlePressed() {
if (widget.onPressed != null)
widget.onPressed(widget.isExpanded);
widget.onPressed!(widget.isExpanded);
}
/// Default icon colors and opacities for when [Theme.brightness] is set to
......@@ -150,29 +148,26 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
/// [Material Design dark theme specifications](https://material.io/design/color/dark-theme.html#ui-application)
Color get _iconColor {
if (widget.isExpanded && widget.expandedColor != null) {
return widget.expandedColor;
return widget.expandedColor!;
}
if (widget.color != null) {
return widget.color;
return widget.color!;
}
switch(Theme.of(context).brightness) {
switch(Theme.of(context)!.brightness) {
case Brightness.light:
return Colors.black54;
case Brightness.dark:
return Colors.white60;
}
assert(false);
return null;
}
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
assert(debugCheckHasMaterialLocalizations(context));
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context)!;
final String onTapHint = widget.isExpanded ? localizations.expandedIconTapHint : localizations.collapsedIconTapHint;
return Semantics(
......
......@@ -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/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -76,8 +74,8 @@ class ExpansionPanel {
///
/// The [headerBuilder], [body], and [isExpanded] arguments must not be null.
ExpansionPanel({
@required this.headerBuilder,
@required this.body,
required this.headerBuilder,
required this.body,
this.isExpanded = false,
this.canTapOnHeader = false,
}) : assert(headerBuilder != null),
......@@ -121,9 +119,9 @@ class ExpansionPanelRadio extends ExpansionPanel {
/// A unique [value] must be passed into the constructor. The
/// [headerBuilder], [body], [value] must not be null.
ExpansionPanelRadio({
@required this.value,
@required ExpansionPanelHeaderBuilder headerBuilder,
@required Widget body,
required this.value,
required ExpansionPanelHeaderBuilder headerBuilder,
required Widget body,
bool canTapOnHeader = false,
}) : assert(value != null),
super(
......@@ -226,7 +224,7 @@ class ExpansionPanelList extends StatefulWidget {
///
/// The [children] and [animationDuration] arguments must not be null.
const ExpansionPanelList({
Key key,
Key? key,
this.children = const <ExpansionPanel>[],
this.expansionCallback,
this.animationDuration = kThemeAnimationDuration,
......@@ -316,7 +314,7 @@ class ExpansionPanelList extends StatefulWidget {
/// ```
/// {@end-tool}
const ExpansionPanelList.radio({
Key key,
Key? key,
this.children = const <ExpansionPanelRadio>[],
this.expansionCallback,
this.animationDuration = kThemeAnimationDuration,
......@@ -349,7 +347,7 @@ class ExpansionPanelList extends StatefulWidget {
///
/// This callback is useful in order to keep track of the expanded/collapsed
/// panels in a parent widget that may need to react to these changes.
final ExpansionPanelCallback expansionCallback;
final ExpansionPanelCallback? expansionCallback;
/// The duration of the expansion animation.
final Duration animationDuration;
......@@ -360,7 +358,7 @@ class ExpansionPanelList extends StatefulWidget {
/// The value of the panel that initially begins open. (This value is
/// only used when initializing with the [ExpansionPanelList.radio]
/// constructor.)
final Object initialOpenPanelValue;
final Object? initialOpenPanelValue;
/// The padding that surrounds the panel header when expanded.
///
......@@ -372,7 +370,7 @@ class ExpansionPanelList extends StatefulWidget {
///
/// If `dividerColor` is null, then [DividerThemeData.color] is used. If that
/// is null, then [ThemeData.dividerColor] is used.
final Color dividerColor;
final Color? dividerColor;
/// Defines elevation for the [ExpansionPanel] while it's expanded.
///
......@@ -390,7 +388,7 @@ class ExpansionPanelList extends StatefulWidget {
}
class _ExpansionPanelListState extends State<ExpansionPanelList> {
ExpansionPanelRadio _currentOpenPanel;
ExpansionPanelRadio? _currentOpenPanel;
@override
void initState() {
......@@ -439,7 +437,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
void _handlePressed(bool isExpanded, int index) {
if (widget.expansionCallback != null)
widget.expansionCallback(index, isExpanded);
widget.expansionCallback!(index, isExpanded);
if (widget._allowOnlyOnePanelOpen) {
final ExpansionPanelRadio pressedChild = widget.children[index] as ExpansionPanelRadio;
......@@ -451,7 +449,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
if (widget.expansionCallback != null &&
childIndex != index &&
child.value == _currentOpenPanel?.value)
widget.expansionCallback(childIndex, false);
widget.expansionCallback!(childIndex, false);
}
setState(() {
......@@ -460,7 +458,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
}
}
ExpansionPanelRadio searchPanelByValue(List<ExpansionPanelRadio> panels, Object value) {
ExpansionPanelRadio? searchPanelByValue(List<ExpansionPanelRadio> panels, Object? value) {
for (final ExpansionPanelRadio panel in panels) {
if (panel.value == value)
return panel;
......@@ -498,7 +496,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
),
);
if (!child.canTapOnHeader) {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context)!;
expandIconContainer = Semantics(
label: _isChildExpanded(index)? localizations.expandedIconTapHint : localizations.collapsedIconTapHint,
container: true,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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