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

migration of material files to nullsafety (#66633)

parent 549de844
......@@ -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;
......@@ -38,15 +36,18 @@ class MaterialPointArcTween extends Tween<Offset> {
/// first used, but the arguments can be null if the values are going to be
/// filled in later.
MaterialPointArcTween({
Offset begin,
Offset end,
Offset? begin,
Offset? end,
}) : super(begin: begin, end: end);
bool _dirty = true;
void _initialize() {
assert(begin != null);
assert(end != null);
assert(this.begin != null);
assert(this.end != null);
final Offset begin = this.begin!;
final Offset end = this.end!;
// An explanation with a diagram can be found at https://goo.gl/vMSdRg
final Offset delta = end - begin;
......@@ -55,12 +56,12 @@ class MaterialPointArcTween extends Tween<Offset> {
final double distanceFromAtoB = delta.distance;
final Offset c = Offset(end.dx, begin.dy);
double sweepAngle() => 2.0 * math.asin(distanceFromAtoB / (2.0 * _radius));
double sweepAngle() => 2.0 * math.asin(distanceFromAtoB / (2.0 * _radius!));
if (deltaX > _kOnAxisDelta && deltaY > _kOnAxisDelta) {
if (deltaX < deltaY) {
_radius = distanceFromAtoB * distanceFromAtoB / (c - begin).distance / 2.0;
_center = Offset(end.dx + _radius * (begin.dx - end.dx).sign, end.dy);
_center = Offset(end.dx + _radius! * (begin.dx - end.dx).sign, end.dy);
if (begin.dx < end.dx) {
_beginAngle = sweepAngle() * (begin.dy - end.dy).sign;
_endAngle = 0.0;
......@@ -70,13 +71,13 @@ class MaterialPointArcTween extends Tween<Offset> {
}
} else {
_radius = distanceFromAtoB * distanceFromAtoB / (c - end).distance / 2.0;
_center = Offset(begin.dx, begin.dy + (end.dy - begin.dy).sign * _radius);
_center = Offset(begin.dx, begin.dy + (end.dy - begin.dy).sign * _radius!);
if (begin.dy < end.dy) {
_beginAngle = -math.pi / 2.0;
_endAngle = _beginAngle + sweepAngle() * (end.dx - begin.dx).sign;
_endAngle = _beginAngle! + sweepAngle() * (end.dx - begin.dx).sign;
} else {
_beginAngle = math.pi / 2.0;
_endAngle = _beginAngle + sweepAngle() * (begin.dx - end.dx).sign;
_endAngle = _beginAngle! + sweepAngle() * (begin.dx - end.dx).sign;
}
}
assert(_beginAngle != null);
......@@ -90,56 +91,56 @@ class MaterialPointArcTween extends Tween<Offset> {
/// The center of the circular arc, null if [begin] and [end] are horizontally or
/// vertically aligned, or if either is null.
Offset get center {
Offset? get center {
if (begin == null || end == null)
return null;
if (_dirty)
_initialize();
return _center;
}
Offset _center;
Offset? _center;
/// The radius of the circular arc, null if [begin] and [end] are horizontally or
/// vertically aligned, or if either is null.
double get radius {
double? get radius {
if (begin == null || end == null)
return null;
if (_dirty)
_initialize();
return _radius;
}
double _radius;
double? _radius;
/// The beginning of the arc's sweep in radians, measured from the positive x
/// axis. Positive angles turn clockwise.
///
/// This will be null if [begin] and [end] are horizontally or vertically
/// aligned, or if either is null.
double get beginAngle {
double? get beginAngle {
if (begin == null || end == null)
return null;
if (_dirty)
_initialize();
return _beginAngle;
}
double _beginAngle;
double? _beginAngle;
/// The end of the arc's sweep in radians, measured from the positive x axis.
/// Positive angles turn clockwise.
///
/// This will be null if [begin] and [end] are horizontally or vertically
/// aligned, or if either is null.
double get endAngle {
double? get endAngle {
if (begin == null || end == null)
return null;
if (_dirty)
_initialize();
return _beginAngle;
}
double _endAngle;
double? _endAngle;
@override
set begin(Offset value) {
set begin(Offset? value) {
if (value != begin) {
super.begin = value;
_dirty = true;
......@@ -147,7 +148,7 @@ class MaterialPointArcTween extends Tween<Offset> {
}
@override
set end(Offset value) {
set end(Offset? value) {
if (value != end) {
super.end = value;
_dirty = true;
......@@ -159,15 +160,15 @@ class MaterialPointArcTween extends Tween<Offset> {
if (_dirty)
_initialize();
if (t == 0.0)
return begin;
return begin!;
if (t == 1.0)
return end;
return end!;
if (_beginAngle == null || _endAngle == null)
return Offset.lerp(begin, end, t);
final double angle = lerpDouble(_beginAngle, _endAngle, t);
final double x = math.cos(angle) * _radius;
final double y = math.sin(angle) * _radius;
return _center + Offset(x, y);
return Offset.lerp(begin, end, t)!;
final double angle = lerpDouble(_beginAngle, _endAngle, t)!;
final double x = math.cos(angle) * _radius!;
final double y = math.sin(angle) * _radius!;
return _center! + Offset(x, y);
}
@override
......@@ -200,8 +201,8 @@ typedef _KeyFunc<T> = double Function(T input);
// Select the element for which the key function returns the maximum value.
T _maxBy<T>(Iterable<T> input, _KeyFunc<T> keyFunc) {
T maxValue;
double maxKey;
late T maxValue;
double? maxKey;
for (final T value in input) {
final double key = keyFunc(value);
if (maxKey == null || key > maxKey) {
......@@ -238,8 +239,8 @@ class MaterialRectArcTween extends RectTween {
/// first used, but the arguments can be null if the values are going to be
/// filled in later.
MaterialRectArcTween({
Rect begin,
Rect end,
Rect? begin,
Rect? end,
}) : super(begin: begin, end: end);
bool _dirty = true;
......@@ -247,21 +248,21 @@ class MaterialRectArcTween extends RectTween {
void _initialize() {
assert(begin != null);
assert(end != null);
final Offset centersVector = end.center - begin.center;
final Offset centersVector = end!.center - begin!.center;
final _Diagonal diagonal = _maxBy<_Diagonal>(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d));
_beginArc = MaterialPointArcTween(
begin: _cornerFor(begin, diagonal.beginId),
end: _cornerFor(end, diagonal.beginId),
begin: _cornerFor(begin!, diagonal.beginId),
end: _cornerFor(end!, diagonal.beginId),
);
_endArc = MaterialPointArcTween(
begin: _cornerFor(begin, diagonal.endId),
end: _cornerFor(end, diagonal.endId),
begin: _cornerFor(begin!, diagonal.endId),
end: _cornerFor(end!, diagonal.endId),
);
_dirty = false;
}
double _diagonalSupport(Offset centersVector, _Diagonal diagonal) {
final Offset delta = _cornerFor(begin, diagonal.endId) - _cornerFor(begin, diagonal.beginId);
final Offset delta = _cornerFor(begin!, diagonal.endId) - _cornerFor(begin!, diagonal.beginId);
final double length = delta.distance;
return centersVector.dx * delta.dx / length + centersVector.dy * delta.dy / length;
}
......@@ -273,33 +274,32 @@ class MaterialRectArcTween extends RectTween {
case _CornerId.bottomLeft: return rect.bottomLeft;
case _CornerId.bottomRight: return rect.bottomRight;
}
return Offset.zero;
}
/// The path of the corresponding [begin], [end] rectangle corners that lead
/// the animation.
MaterialPointArcTween get beginArc {
MaterialPointArcTween? get beginArc {
if (begin == null)
return null;
if (_dirty)
_initialize();
return _beginArc;
}
MaterialPointArcTween _beginArc;
late MaterialPointArcTween _beginArc;
/// The path of the corresponding [begin], [end] rectangle corners that trail
/// the animation.
MaterialPointArcTween get endArc {
MaterialPointArcTween? get endArc {
if (end == null)
return null;
if (_dirty)
_initialize();
return _endArc;
}
MaterialPointArcTween _endArc;
late MaterialPointArcTween _endArc;
@override
set begin(Rect value) {
set begin(Rect? value) {
if (value != begin) {
super.begin = value;
_dirty = true;
......@@ -307,7 +307,7 @@ class MaterialRectArcTween extends RectTween {
}
@override
set end(Rect value) {
set end(Rect? value) {
if (value != end) {
super.end = value;
_dirty = true;
......@@ -319,9 +319,9 @@ class MaterialRectArcTween extends RectTween {
if (_dirty)
_initialize();
if (t == 0.0)
return begin;
return begin!;
if (t == 1.0)
return end;
return end!;
return Rect.fromPoints(_beginArc.lerp(t), _endArc.lerp(t));
}
......@@ -354,8 +354,8 @@ class MaterialRectCenterArcTween extends RectTween {
/// first used, but the arguments can be null if the values are going to be
/// filled in later.
MaterialRectCenterArcTween({
Rect begin,
Rect end,
Rect? begin,
Rect? end,
}) : super(begin: begin, end: end);
bool _dirty = true;
......@@ -364,25 +364,25 @@ class MaterialRectCenterArcTween extends RectTween {
assert(begin != null);
assert(end != null);
_centerArc = MaterialPointArcTween(
begin: begin.center,
end: end.center,
begin: begin!.center,
end: end!.center,
);
_dirty = false;
}
/// If [begin] and [end] are non-null, returns a tween that interpolates along
/// a circular arc between [begin]'s [Rect.center] and [end]'s [Rect.center].
MaterialPointArcTween get centerArc {
MaterialPointArcTween? get centerArc {
if (begin == null || end == null)
return null;
if (_dirty)
_initialize();
return _centerArc;
}
MaterialPointArcTween _centerArc;
late MaterialPointArcTween _centerArc;
@override
set begin(Rect value) {
set begin(Rect? value) {
if (value != begin) {
super.begin = value;
_dirty = true;
......@@ -390,7 +390,7 @@ class MaterialRectCenterArcTween extends RectTween {
}
@override
set end(Rect value) {
set end(Rect? value) {
if (value != end) {
super.end = value;
_dirty = true;
......@@ -402,12 +402,12 @@ class MaterialRectCenterArcTween extends RectTween {
if (_dirty)
_initialize();
if (t == 0.0)
return begin;
return begin!;
if (t == 1.0)
return end;
return end!;
final Offset center = _centerArc.lerp(t);
final double width = lerpDouble(begin.width, end.width, t);
final double height = lerpDouble(begin.height, end.height, t);
final double width = lerpDouble(begin!.width, end!.width, t)!;
final double height = lerpDouble(begin!.height, end!.height, t)!;
return Rect.fromLTWH(center.dx - width / 2.0, center.dy - height / 2.0, width, height);
}
......
......@@ -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';
......@@ -41,43 +39,43 @@ class BottomSheetThemeData with Diagnosticable {
/// Default value for [BottomSheet.backgroundColor].
///
/// If null, [BottomSheet] defaults to [Material]'s default.
final Color backgroundColor;
final Color? backgroundColor;
/// Default value for [BottomSheet.elevation].
///
/// {@macro flutter.material.material.elevation}
///
/// If null, [BottomSheet] defaults to 0.0.
final double elevation;
final double? elevation;
/// Value for [BottomSheet.backgroundColor] when the Bottom sheet is presented
/// as a modal bottom sheet.
final Color modalBackgroundColor;
final Color? modalBackgroundColor;
/// Value for [BottomSheet.elevation] when the Bottom sheet is presented as a
/// modal bottom sheet.
final double modalElevation;
final double? modalElevation;
/// Default value for [BottomSheet.shape].
///
/// If null, no overriding shape is specified for [BottomSheet], so the
/// [BottomSheet] is rectangular.
final ShapeBorder shape;
final ShapeBorder? shape;
/// Default value for [BottomSheet.clipBehavior].
///
/// If null, [BottomSheet] uses [Clip.none].
final Clip clipBehavior;
final Clip? clipBehavior;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
BottomSheetThemeData copyWith({
Color backgroundColor,
double elevation,
Color modalBackgroundColor,
double modalElevation,
ShapeBorder shape,
Clip clipBehavior,
Color? backgroundColor,
double? elevation,
Color? modalBackgroundColor,
double? modalElevation,
ShapeBorder? shape,
Clip? clipBehavior,
}) {
return BottomSheetThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -94,7 +92,7 @@ class BottomSheetThemeData with Diagnosticable {
/// If both arguments are null then null is returned.
///
/// {@macro dart.ui.shadow.lerp}
static BottomSheetThemeData lerp(BottomSheetThemeData a, BottomSheetThemeData b, double t) {
static BottomSheetThemeData? lerp(BottomSheetThemeData? a, BottomSheetThemeData? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......
......@@ -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;
import 'package:flutter/painting.dart';
......@@ -27,34 +25,34 @@ class MaterialColor extends ColorSwatch<int> {
const MaterialColor(int primary, Map<int, Color> swatch) : super(primary, swatch);
/// The lightest shade.
Color get shade50 => this[50];
Color get shade50 => this[50]!;
/// The second lightest shade.
Color get shade100 => this[100];
Color get shade100 => this[100]!;
/// The third lightest shade.
Color get shade200 => this[200];
Color get shade200 => this[200]!;
/// The fourth lightest shade.
Color get shade300 => this[300];
Color get shade300 => this[300]!;
/// The fifth lightest shade.
Color get shade400 => this[400];
Color get shade400 => this[400]!;
/// The default shade.
Color get shade500 => this[500];
Color get shade500 => this[500]!;
/// The fourth darkest shade.
Color get shade600 => this[600];
Color get shade600 => this[600]!;
/// The third darkest shade.
Color get shade700 => this[700];
Color get shade700 => this[700]!;
/// The second darkest shade.
Color get shade800 => this[800];
Color get shade800 => this[800]!;
/// The darkest shade.
Color get shade900 => this[900];
Color get shade900 => this[900]!;
}
/// Defines a single accent color as well a swatch of four shades of the
......@@ -75,19 +73,19 @@ class MaterialAccentColor extends ColorSwatch<int> {
const MaterialAccentColor(int primary, Map<int, Color> swatch) : super(primary, swatch);
/// The lightest shade.
Color get shade50 => this[50];
Color get shade50 => this[50]!;
/// The second lightest shade.
Color get shade100 => this[100];
Color get shade100 => this[100]!;
/// The default shade.
Color get shade200 => this[200];
Color get shade200 => this[200]!;
/// The second darkest shade.
Color get shade400 => this[400];
Color get shade400 => this[400]!;
/// The darkest shade.
Color get shade700 => this[700];
Color get shade700 => this[700]!;
}
/// [Color] and [ColorSwatch] constants which represent Material design's
......
......@@ -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/painting.dart';
/// The minimum dimension of any interactive region according to Material
......
......@@ -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/animation.dart';
// The easing curves of the Material Library
......
......@@ -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';
......@@ -48,63 +46,63 @@ class FloatingActionButtonThemeData with Diagnosticable {
/// Color to be used for the unselected, enabled [FloatingActionButton]'s
/// foreground.
final Color foregroundColor;
final Color? foregroundColor;
/// Color to be used for the unselected, enabled [FloatingActionButton]'s
/// background.
final Color backgroundColor;
final Color? backgroundColor;
/// The color to use for filling the button when the button has input focus.
final Color focusColor;
final Color? focusColor;
/// The color to use for filling the button when the button has a pointer
/// hovering over it.
final Color hoverColor;
final Color? hoverColor;
/// The splash color for this [FloatingActionButton]'s [InkWell].
final Color splashColor;
final Color? splashColor;
/// The z-coordinate to be used for the unselected, enabled
/// [FloatingActionButton]'s elevation foreground.
final double elevation;
final double? elevation;
/// The z-coordinate at which to place this button relative to its parent when
/// the button has the input focus.
///
/// This controls the size of the shadow below the floating action button.
final double focusElevation;
final double? focusElevation;
/// The z-coordinate at which to place this button relative to its parent when
/// the button is enabled and has a pointer hovering over it.
///
/// This controls the size of the shadow below the floating action button.
final double hoverElevation;
final double? hoverElevation;
/// The z-coordinate to be used for the disabled [FloatingActionButton]'s
/// elevation foreground.
final double disabledElevation;
final double? disabledElevation;
/// The z-coordinate to be used for the selected, enabled
/// [FloatingActionButton]'s elevation foreground.
final double highlightElevation;
final double? highlightElevation;
/// The shape to be used for the floating action button's [Material].
final ShapeBorder shape;
final ShapeBorder? shape;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
FloatingActionButtonThemeData copyWith({
Color foregroundColor,
Color backgroundColor,
Color focusColor,
Color hoverColor,
Color splashColor,
double elevation,
double focusElevation,
double hoverElevation,
double disabledElevation,
double highlightElevation,
ShapeBorder shape,
Color? foregroundColor,
Color? backgroundColor,
Color? focusColor,
Color? hoverColor,
Color? splashColor,
double? elevation,
double? focusElevation,
double? hoverElevation,
double? disabledElevation,
double? highlightElevation,
ShapeBorder? shape,
}) {
return FloatingActionButtonThemeData(
foregroundColor: foregroundColor ?? this.foregroundColor,
......@@ -126,7 +124,7 @@ class FloatingActionButtonThemeData with Diagnosticable {
/// If both arguments are null then null is returned.
///
/// {@macro dart.ui.shadow.lerp}
static FloatingActionButtonThemeData lerp(FloatingActionButtonThemeData a, FloatingActionButtonThemeData b, double t) {
static FloatingActionButtonThemeData? lerp(FloatingActionButtonThemeData? a, FloatingActionButtonThemeData? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......
......@@ -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';
/// The Flutter logo, in widget form. This widget respects the [IconTheme].
......@@ -22,7 +20,7 @@ class FlutterLogo extends StatelessWidget {
/// The [textColor], [style], [duration], and [curve] arguments must not be
/// null.
const FlutterLogo({
Key key,
Key? key,
this.size,
this.textColor = const Color(0xFF757575),
this.style = FlutterLogoStyle.markOnly,
......@@ -41,7 +39,7 @@ class FlutterLogo extends StatelessWidget {
/// Defaults to the current [IconTheme] size, if any. If there is no
/// [IconTheme], or it does not specify an explicit size, then it defaults to
/// 24.0.
final double size;
final double? size;
/// The color used to paint the "Flutter" text on the logo, if [style] is
/// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked].
......@@ -64,7 +62,7 @@ class FlutterLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
final IconThemeData iconTheme = IconTheme.of(context);
final double iconSize = size ?? iconTheme.size;
final double? iconSize = size ?? iconTheme.size;
return AnimatedContainer(
width: iconSize,
height: iconSize,
......
......@@ -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';
/// A tile in a material design grid list.
......@@ -23,22 +21,22 @@ class GridTile extends StatelessWidget {
///
/// Must have a child. Does not typically have both a header and a footer.
const GridTile({
Key key,
Key? key,
this.header,
this.footer,
@required this.child,
required this.child,
}) : assert(child != null),
super(key: key);
/// The widget to show over the top of this grid tile.
///
/// Typically a [GridTileBar].
final Widget header;
final Widget? header;
/// The widget to show over the bottom of this grid tile.
///
/// Typically a [GridTileBar].
final Widget footer;
final Widget? footer;
/// The widget that fills the tile.
///
......@@ -60,14 +58,14 @@ class GridTile extends StatelessWidget {
top: 0.0,
left: 0.0,
right: 0.0,
child: header,
child: header!,
),
if (footer != null)
Positioned(
left: 0.0,
bottom: 0.0,
right: 0.0,
child: footer,
child: footer!,
),
],
);
......
......@@ -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';
/// Identifiers for the supported material design icons.
......@@ -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;
import 'package:flutter/foundation.dart';
......@@ -76,7 +74,7 @@ enum MaterialState {
/// Signature for the function that returns a value of type `T` based on a given
/// set of states.
typedef MaterialPropertyResolver<T> = T Function(Set<MaterialState> states);
typedef MaterialPropertyResolver<T> = T? Function(Set<MaterialState> states);
/// Defines a [Color] that is also a [MaterialStateProperty].
///
......@@ -139,7 +137,7 @@ abstract class MaterialStateColor extends Color implements MaterialStateProperty
/// Returns a [Color] that's to be used when a Material component is in the
/// specified state.
@override
Color resolve(Set<MaterialState> states);
Color? resolve(Set<MaterialState> states);
}
/// A [MaterialStateColor] created from a [MaterialPropertyResolver<Color>]
......@@ -150,7 +148,7 @@ abstract class MaterialStateColor extends Color implements MaterialStateProperty
///
/// Used by [MaterialStateColor.resolveWith].
class _MaterialStateColor extends MaterialStateColor {
_MaterialStateColor(this._resolve) : super(_resolve(_defaultStates).value);
_MaterialStateColor(this._resolve) : super(_resolve(_defaultStates)!.value);
final MaterialPropertyResolver<Color> _resolve;
......@@ -158,7 +156,7 @@ class _MaterialStateColor extends MaterialStateColor {
static const Set<MaterialState> _defaultStates = <MaterialState>{};
@override
Color resolve(Set<MaterialState> states) => _resolve(states);
Color? resolve(Set<MaterialState> states) => _resolve(states);
}
/// Defines a [MouseCursor] whose value depends on a set of [MaterialState]s which
......@@ -224,7 +222,7 @@ abstract class MaterialStateMouseCursor extends MouseCursor implements MaterialS
@protected
@override
MouseCursorSession createSession(int device) {
return resolve(<MaterialState>{}).createSession(device);
return resolve(<MaterialState>{})!.createSession(device);
}
/// Returns a [MouseCursor] that's to be used when a Material component is in
......@@ -232,7 +230,7 @@ abstract class MaterialStateMouseCursor extends MouseCursor implements MaterialS
///
/// This method should never return null.
@override
MouseCursor resolve(Set<MaterialState> states);
MouseCursor? resolve(Set<MaterialState> states);
/// A mouse cursor for clickable material widgets, which resolves differently
/// when the widget is disabled.
......@@ -263,9 +261,9 @@ abstract class MaterialStateMouseCursor extends MouseCursor implements MaterialS
class _EnabledAndDisabledMouseCursor extends MaterialStateMouseCursor {
const _EnabledAndDisabledMouseCursor({
this.enabledCursor,
this.disabledCursor,
this.name,
required this.enabledCursor,
required this.disabledCursor,
required this.name,
});
final MouseCursor enabledCursor;
......@@ -349,7 +347,7 @@ abstract class MaterialStateProperty<T> {
/// Widgets like [TextButton] and [ElevatedButton] apply this method to their
/// current [MaterialState]s to compute colors and other visual parameters
/// at build time.
T resolve(Set<MaterialState> states);
T? resolve(Set<MaterialState> states);
/// Resolves the value for the given set of states if `value` is a
/// [MaterialStateProperty], otherwise returns the value itself.
......@@ -357,9 +355,9 @@ abstract class MaterialStateProperty<T> {
/// This is useful for widgets that have parameters which can optionally be a
/// [MaterialStateProperty]. For example, [InkWell.mouseCursor] can be a
/// [MouseCursor] or a [MaterialStateProperty<MouseCursor>].
static T resolveAs<T>(T value, Set<MaterialState> states) {
static T? resolveAs<T>(T? value, Set<MaterialState> states) {
if (value is MaterialStateProperty<T>) {
final MaterialStateProperty<T> property = value;
final MaterialStateProperty<T> property = value as MaterialStateProperty<T>;
return property.resolve(states);
}
return value;
......@@ -371,7 +369,7 @@ abstract class MaterialStateProperty<T> {
/// Convenience method for creating a [MaterialStateProperty] that resolves
/// to a single value for all states.
static MaterialStateProperty<T> all<T>(T value) => _MaterialStatePropertyAll<T>(value);
static MaterialStateProperty<T> all<T>(T? value) => _MaterialStatePropertyAll<T>(value);
}
class _MaterialStatePropertyWith<T> implements MaterialStateProperty<T> {
......@@ -380,16 +378,16 @@ class _MaterialStatePropertyWith<T> implements MaterialStateProperty<T> {
final MaterialPropertyResolver<T> _resolve;
@override
T resolve(Set<MaterialState> states) => _resolve(states);
T? resolve(Set<MaterialState> states) => _resolve(states);
}
class _MaterialStatePropertyAll<T> implements MaterialStateProperty<T> {
_MaterialStatePropertyAll(this.value);
final T value;
final T? value;
@override
T resolve(Set<MaterialState> states) => value;
T? resolve(Set<MaterialState> states) => value;
@override
String toString() => 'MaterialStateProperty.all($value)';
......
......@@ -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/painting.dart';
......@@ -113,16 +111,16 @@ class TextTheme with Diagnosticable {
/// If you do decide to create your own text theme, consider using one of
/// those predefined themes as a starting point for [copyWith] or [apply].
const TextTheme({
TextStyle headline1,
TextStyle headline2,
TextStyle headline3,
TextStyle headline4,
TextStyle headline5,
TextStyle headline6,
TextStyle subtitle1,
TextStyle subtitle2,
TextStyle bodyText1,
TextStyle bodyText2,
TextStyle? headline1,
TextStyle? headline2,
TextStyle? headline3,
TextStyle? headline4,
TextStyle? headline5,
TextStyle? headline6,
TextStyle? subtitle1,
TextStyle? subtitle2,
TextStyle? bodyText1,
TextStyle? bodyText2,
this.caption,
this.button,
this.overline,
......@@ -130,52 +128,52 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display4,
TextStyle? display4,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display3,
TextStyle? display3,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline3. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display2,
TextStyle? display2,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline4. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display1,
TextStyle? display1,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline5. '
'This feature was deprecated after v1.13.8.'
)
TextStyle headline,
TextStyle? headline,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline6. '
'This feature was deprecated after v1.13.8.'
)
TextStyle title,
TextStyle? title,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle subhead,
TextStyle? subhead,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle subtitle,
TextStyle? subtitle,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle body2,
TextStyle? body2,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle body1,
TextStyle? body1,
}) : assert(
(headline1 == null && headline2 == null && headline3 == null && headline4 == null && headline5 == null && headline6 == null &&
subtitle1 == null && subtitle2 == null &&
......@@ -195,49 +193,49 @@ class TextTheme with Diagnosticable {
bodyText2 = bodyText2 ?? body1;
/// Extremely large text.
final TextStyle headline1;
final TextStyle? headline1;
/// Very, very large text.
///
/// Used for the date in the dialog shown by [showDatePicker].
final TextStyle headline2;
final TextStyle? headline2;
/// Very large text.
final TextStyle headline3;
final TextStyle? headline3;
/// Large text.
final TextStyle headline4;
final TextStyle? headline4;
/// Used for large text in dialogs (e.g., the month and year in the dialog
/// shown by [showDatePicker]).
final TextStyle headline5;
final TextStyle? headline5;
/// Used for the primary text in app bars and dialogs (e.g., [AppBar.title]
/// and [AlertDialog.title]).
final TextStyle headline6;
final TextStyle? headline6;
/// Used for the primary text in lists (e.g., [ListTile.title]).
final TextStyle subtitle1;
final TextStyle? subtitle1;
/// For medium emphasis text that's a little smaller than [subtitle1].
final TextStyle subtitle2;
final TextStyle? subtitle2;
/// Used for emphasizing text that would otherwise be [bodyText2].
final TextStyle bodyText1;
final TextStyle? bodyText1;
/// The default text style for [Material].
final TextStyle bodyText2;
final TextStyle? bodyText2;
/// Used for auxiliary text associated with images.
final TextStyle caption;
final TextStyle? caption;
/// Used for text on [ElevatedButton], [TextButton] and [OutlinedButton].
final TextStyle button;
final TextStyle? button;
/// The smallest style.
///
/// Typically used for captions or to introduce a (larger) headline.
final TextStyle overline;
final TextStyle? overline;
/// Extremely large text.
///
......@@ -247,7 +245,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get display4 => headline1;
TextStyle? get display4 => headline1;
/// Very, very large text.
///
......@@ -257,7 +255,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get display3 => headline2;
TextStyle? get display3 => headline2;
/// Very large text.
///
......@@ -267,7 +265,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline3. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get display2 => headline3;
TextStyle? get display2 => headline3;
/// Large text.
///
......@@ -277,7 +275,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline4. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get display1 => headline4;
TextStyle? get display1 => headline4;
/// Used for large text in dialogs.
///
......@@ -287,7 +285,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline5. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get headline => headline5;
TextStyle? get headline => headline5;
/// Used for the primary text in app bars and dialogs.
///
......@@ -297,7 +295,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is headline6. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get title => headline6;
TextStyle? get title => headline6;
/// Used for the primary text in lists (e.g., [ListTile.title]).
///
......@@ -307,7 +305,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get subhead => subtitle1;
TextStyle? get subhead => subtitle1;
/// For medium emphasis text that's a little smaller than [subhead].
///
......@@ -317,7 +315,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get subtitle => subtitle2;
TextStyle? get subtitle => subtitle2;
/// Used for emphasizing text that would otherwise be [body1].
///
......@@ -328,7 +326,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get body2 => bodyText1;
TextStyle? get body2 => bodyText1;
/// Used for the default text style for [Material].
///
......@@ -339,7 +337,7 @@ class TextTheme with Diagnosticable {
'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle get body1 => bodyText2;
TextStyle? get body1 => bodyText2;
/// Creates a copy of this text theme but with the given fields replaced with
......@@ -383,69 +381,69 @@ class TextTheme with Diagnosticable {
/// * [merge] is used instead of [copyWith] when you want to merge all
/// of the fields of a TextTheme instead of individual fields.
TextTheme copyWith({
TextStyle headline1,
TextStyle headline2,
TextStyle headline3,
TextStyle headline4,
TextStyle headline5,
TextStyle headline6,
TextStyle subtitle1,
TextStyle subtitle2,
TextStyle bodyText1,
TextStyle bodyText2,
TextStyle caption,
TextStyle button,
TextStyle overline,
TextStyle? headline1,
TextStyle? headline2,
TextStyle? headline3,
TextStyle? headline4,
TextStyle? headline5,
TextStyle? headline6,
TextStyle? subtitle1,
TextStyle? subtitle2,
TextStyle? bodyText1,
TextStyle? bodyText2,
TextStyle? caption,
TextStyle? button,
TextStyle? overline,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display4,
TextStyle? display4,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display3,
TextStyle? display3,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline3. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display2,
TextStyle? display2,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline4. '
'This feature was deprecated after v1.13.8.'
)
TextStyle display1,
TextStyle? display1,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline5. '
'This feature was deprecated after v1.13.8.'
)
TextStyle headline,
TextStyle? headline,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is headline6. '
'This feature was deprecated after v1.13.8.'
)
TextStyle title,
TextStyle? title,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is subtitle1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle subhead,
TextStyle? subhead,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is subtitle2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle subtitle,
TextStyle? subtitle,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is bodyText1. '
'This feature was deprecated after v1.13.8.'
)
TextStyle body2,
TextStyle? body2,
@Deprecated(
'This is the term used in the 2014 version of material design. The modern term is bodyText2. '
'This feature was deprecated after v1.13.8.'
)
TextStyle body1,
TextStyle? body1,
}) {
assert(
(headline1 == null && headline2 == null && headline3 == null && headline4 == null && headline5 == null && headline6 == null &&
......@@ -522,7 +520,7 @@ class TextTheme with Diagnosticable {
/// * [copyWith] is used instead of [merge] when you wish to override
/// individual fields in the [TextTheme] instead of merging all of the
/// fields of two [TextTheme]s.
TextTheme merge(TextTheme other) {
TextTheme merge(TextTheme? other) {
if (other == null)
return this;
return copyWith(
......@@ -553,14 +551,14 @@ class TextTheme with Diagnosticable {
/// the typography styles in the material design specification, as a starting
/// point.
TextTheme apply({
String fontFamily,
String? fontFamily,
double fontSizeFactor = 1.0,
double fontSizeDelta = 0.0,
Color displayColor,
Color bodyColor,
TextDecoration decoration,
Color decorationColor,
TextDecorationStyle decorationStyle,
Color? displayColor,
Color? bodyColor,
TextDecoration? decoration,
Color? decorationColor,
TextDecorationStyle? decorationStyle,
}) {
return TextTheme(
headline1: headline1?.apply(
......@@ -686,7 +684,7 @@ class TextTheme with Diagnosticable {
/// Linearly interpolate between two text themes.
///
/// {@macro dart.ui.shadow.lerp}
static TextTheme lerp(TextTheme a, TextTheme b, double t) {
static TextTheme lerp(TextTheme? a, TextTheme? b, double t) {
assert(t != null);
return TextTheme(
headline1: TextStyle.lerp(a?.headline1, b?.headline1, 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/animation.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
......@@ -32,15 +30,15 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// The [activeColor], and [inactiveColor] arguments must not be
/// null. The [value] can only be null if tristate is true.
RenderToggleable({
@required bool value,
required bool? value,
bool tristate = false,
@required Color activeColor,
@required Color inactiveColor,
Color hoverColor,
Color focusColor,
ValueChanged<bool> onChanged,
BoxConstraints additionalConstraints,
@required TickerProvider vsync,
required Color activeColor,
required Color inactiveColor,
Color? hoverColor,
Color? focusColor,
ValueChanged<bool?>? onChanged,
required BoxConstraints additionalConstraints,
required TickerProvider vsync,
bool hasFocus = false,
bool hovering = false,
}) : assert(tristate != null),
......@@ -110,7 +108,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// animation reaches either 0.0 or 1.0.
@protected
AnimationController get positionController => _positionController;
AnimationController _positionController;
late AnimationController _positionController;
/// The visual value of the control.
///
......@@ -121,7 +119,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// to active (or vice versa), [value] is the target value and this animation
/// gradually updates from 0.0 to 1.0 (or vice versa).
CurvedAnimation get position => _position;
CurvedAnimation _position;
late CurvedAnimation _position;
/// Used by subclasses to control the radial reaction animation.
///
......@@ -132,8 +130,8 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// reaction.
@protected
AnimationController get reactionController => _reactionController;
AnimationController _reactionController;
Animation<double> _reaction;
late AnimationController _reactionController;
late Animation<double> _reaction;
/// Used by subclasses to control the radial reaction's opacity animation for
/// [hasFocus] changes.
......@@ -146,8 +144,8 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// reaction.
@protected
AnimationController get reactionFocusFadeController => _reactionFocusFadeController;
AnimationController _reactionFocusFadeController;
Animation<double> _reactionFocusFade;
late AnimationController _reactionFocusFadeController;
late Animation<double> _reactionFocusFade;
/// Used by subclasses to control the radial reaction's opacity animation for
/// [hovering] changes.
......@@ -160,8 +158,8 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// reaction.
@protected
AnimationController get reactionHoverFadeController => _reactionHoverFadeController;
AnimationController _reactionHoverFadeController;
Animation<double> _reactionHoverFade;
late AnimationController _reactionHoverFadeController;
late Animation<double> _reactionHoverFade;
/// True if this toggleable has the input focus.
bool get hasFocus => _hasFocus;
......@@ -216,9 +214,9 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// When the value changes, this object starts the [positionController] and
/// [position] animations to animate the visual appearance of the control to
/// the new value.
bool get value => _value;
bool _value;
set value(bool value) {
bool? get value => _value;
bool? _value;
set value(bool? value) {
assert(tristate || value != null);
if (value == _value)
return;
......@@ -323,9 +321,9 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// that is displayed when the toggleable is toggled by a tap.
///
/// Defaults to the [activeColor] at alpha [kRadialReactionAlpha].
Color get reactionColor => _reactionColor;
Color _reactionColor;
set reactionColor(Color value) {
Color? get reactionColor => _reactionColor;
Color? _reactionColor;
set reactionColor(Color? value) {
assert(value != null);
if (value == _reactionColor)
return;
......@@ -342,9 +340,9 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// callback is non-null. If the callback is null, then the control is
/// disabled, and non-interactive. A disabled checkbox, for example, is
/// displayed using a grey color and its value cannot be changed.
ValueChanged<bool> get onChanged => _onChanged;
ValueChanged<bool> _onChanged;
set onChanged(ValueChanged<bool> value) {
ValueChanged<bool?>? get onChanged => _onChanged;
ValueChanged<bool?>? _onChanged;
set onChanged(ValueChanged<bool?>? value) {
if (value == _onChanged)
return;
final bool wasInteractive = isInteractive;
......@@ -363,8 +361,8 @@ abstract class RenderToggleable extends RenderConstrainedBox {
/// grey color and its value cannot be changed.
bool get isInteractive => onChanged != null;
TapGestureRecognizer _tap;
Offset _downPosition;
late TapGestureRecognizer _tap;
Offset? _downPosition;
@override
void attach(PipelineOwner owner) {
......@@ -410,13 +408,13 @@ abstract class RenderToggleable extends RenderConstrainedBox {
return;
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;
}
sendSemanticsEvent(const TapSemanticEvent());
......@@ -457,8 +455,8 @@ abstract class RenderToggleable extends RenderConstrainedBox {
Color.lerp(activeColor.withAlpha(kRadialReactionAlpha), hoverColor, _reactionHoverFade.value),
focusColor,
_reactionFocusFade.value,
);
final Offset center = Offset.lerp(_downPosition ?? origin, origin, _reaction.value);
)!;
final Offset center = Offset.lerp(_downPosition ?? origin, origin, _reaction.value)!;
final double reactionRadius = hasFocus || hovering
? kRadialReactionRadius
: _kRadialReactionRadiusTween.evaluate(_reaction);
......
......@@ -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/painting.dart';
......@@ -117,12 +115,12 @@ class Typography with Diagnosticable {
/// The default values for [englishLike], [dense], and [tall] are
/// [englishLike2014], [dense2014], and [tall2014].
factory Typography.material2014({
TargetPlatform platform = TargetPlatform.android,
TextTheme black,
TextTheme white,
TextTheme englishLike,
TextTheme dense,
TextTheme tall,
TargetPlatform? platform = TargetPlatform.android,
TextTheme? black,
TextTheme? white,
TextTheme? englishLike,
TextTheme? dense,
TextTheme? tall,
}) {
assert(platform != null || (black != null && white != null));
return Typography._withPlatform(
......@@ -145,12 +143,12 @@ class Typography with Diagnosticable {
/// The default values for [englishLike], [dense], and [tall] are
/// [englishLike2018], [dense2018], and [tall2018].
factory Typography.material2018({
TargetPlatform platform = TargetPlatform.android,
TextTheme black,
TextTheme white,
TextTheme englishLike,
TextTheme dense,
TextTheme tall,
TargetPlatform? platform = TargetPlatform.android,
TextTheme? black,
TextTheme? white,
TextTheme? englishLike,
TextTheme? dense,
TextTheme? tall,
}) {
assert(platform != null || (black != null && white != null));
return Typography._withPlatform(
......@@ -163,9 +161,9 @@ class Typography with Diagnosticable {
}
factory Typography._withPlatform(
TargetPlatform platform,
TextTheme black,
TextTheme white,
TargetPlatform? platform,
TextTheme? black,
TextTheme? white,
TextTheme englishLike,
TextTheme dense,
TextTheme tall,
......@@ -193,8 +191,10 @@ class Typography with Diagnosticable {
black ??= blackHelsinki;
white ??= whiteHelsinki;
break;
case null:
break;
}
return Typography._(black, white, englishLike, dense, tall);
return Typography._(black!, white!, englishLike, dense, tall);
}
const Typography._(this.black, this.white, this.englishLike, this.dense, this.tall)
......@@ -269,17 +269,16 @@ class Typography with Diagnosticable {
case ScriptCategory.tall:
return tall;
}
return null;
}
/// Creates a copy of this [Typography] with the given fields
/// replaced by the non-null parameter values.
Typography copyWith({
TextTheme black,
TextTheme white,
TextTheme englishLike,
TextTheme dense,
TextTheme tall,
TextTheme? black,
TextTheme? white,
TextTheme? englishLike,
TextTheme? dense,
TextTheme? tall,
}) {
return Typography._(
black ?? this.black,
......
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