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

migrate some material files to nullsafty (#66858)

* migrate some material files to nullsafty

* address review comments
parent 0e9c6a3d
......@@ -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';
......@@ -46,44 +44,44 @@ class CardTheme with Diagnosticable {
/// Default value for [Card.clipBehavior].
///
/// If null, [Card] uses [Clip.none].
final Clip clipBehavior;
final Clip? clipBehavior;
/// Default value for [Card.color].
///
/// If null, [Card] uses [ThemeData.cardColor].
final Color color;
final Color? color;
/// Default value for [Card.shadowColor].
///
/// If null, [Card] defaults to fully opaque black.
final Color shadowColor;
final Color? shadowColor;
/// Default value for [Card.elevation].
///
/// If null, [Card] uses a default of 1.0.
final double elevation;
final double? elevation;
/// Default value for [Card.margin].
///
/// If null, [Card] uses a default margin of 4.0 logical pixels on all sides:
/// `EdgeInsets.all(4.0)`.
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// Default value for [Card.shape].
///
/// If null, [Card] then uses a [RoundedRectangleBorder] with a circular
/// corner radius of 4.0.
final ShapeBorder shape;
final ShapeBorder? shape;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
CardTheme copyWith({
Clip clipBehavior,
Color color,
Color shadowColor,
double elevation,
EdgeInsetsGeometry margin,
ShapeBorder shape,
Clip? clipBehavior,
Color? color,
Color? shadowColor,
double? elevation,
EdgeInsetsGeometry? margin,
ShapeBorder? shape,
}) {
return CardTheme(
clipBehavior: clipBehavior ?? this.clipBehavior,
......@@ -97,7 +95,7 @@ class CardTheme with Diagnosticable {
/// The [ThemeData.cardTheme] property of the ambient [Theme].
static CardTheme of(BuildContext context) {
return Theme.of(context).cardTheme;
return Theme.of(context)!.cardTheme;
}
/// Linearly interpolate between two Card themes.
......@@ -105,7 +103,7 @@ class CardTheme with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static CardTheme lerp(CardTheme a, CardTheme b, double t) {
static CardTheme lerp(CardTheme? a, CardTheme? b, double t) {
assert(t != null);
return CardTheme(
clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior,
......
......@@ -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';
......
......@@ -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';
......@@ -45,7 +43,7 @@ class ElevationOverlay {
/// * <https://material.io/design/color/dark-theme.html>, which specifies how
/// the overlay should be applied.
static Color applyOverlay(BuildContext context, Color color, double elevation) {
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
if (elevation > 0.0 &&
theme.applyElevationOverlayColor &&
theme.brightness == Brightness.dark &&
......@@ -63,7 +61,7 @@ class ElevationOverlay {
/// * https://material.io/design/color/dark-theme.html#properties which
/// specifies the exact overlay values for a given elevation.
static Color overlayColor(BuildContext context, double elevation) {
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
// Compute the opacity for the given elevation
// This formula matches the values in the spec:
// https://material.io/design/color/dark-theme.html#properties
......
......@@ -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/semantics.dart';
import 'package:flutter/services.dart';
......@@ -94,7 +92,7 @@ class Feedback {
/// * [wrapForTap] to trigger platform-specific feedback before executing a
/// [GestureTapCallback].
static Future<void> forTap(BuildContext context) async {
context.findRenderObject().sendSemanticsEvent(const TapSemanticEvent());
context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent());
switch (_platform(context)) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
......@@ -104,10 +102,7 @@ class Feedback {
case TargetPlatform.macOS:
case TargetPlatform.windows:
return Future<void>.value();
break;
}
assert(false, 'Unhandled TargetPlatform ${_platform(context)}');
return Future<void>.value();
}
/// Wraps a [GestureTapCallback] to provide platform specific feedback for a
......@@ -120,7 +115,7 @@ class Feedback {
///
/// * [forTap] to just trigger the platform-specific feedback without wrapping
/// a [GestureTapCallback].
static GestureTapCallback wrapForTap(GestureTapCallback callback, BuildContext context) {
static GestureTapCallback? wrapForTap(GestureTapCallback? callback, BuildContext context) {
if (callback == null)
return null;
return () {
......@@ -139,7 +134,7 @@ class Feedback {
/// * [wrapForLongPress] to trigger platform-specific feedback before
/// executing a [GestureLongPressCallback].
static Future<void> forLongPress(BuildContext context) {
context.findRenderObject().sendSemanticsEvent(const LongPressSemanticsEvent());
context.findRenderObject()!.sendSemanticsEvent(const LongPressSemanticsEvent());
switch (_platform(context)) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
......@@ -149,10 +144,7 @@ class Feedback {
case TargetPlatform.macOS:
case TargetPlatform.windows:
return Future<void>.value();
break;
}
assert(false, 'Unhandled TargetPlatform ${_platform(context)}');
return Future<void>.value();
}
/// Wraps a [GestureLongPressCallback] to provide platform specific feedback
......@@ -166,7 +158,7 @@ class Feedback {
///
/// * [forLongPress] to just trigger the platform-specific feedback without
/// wrapping a [GestureLongPressCallback].
static GestureLongPressCallback wrapForLongPress(GestureLongPressCallback callback, BuildContext context) {
static GestureLongPressCallback? wrapForLongPress(GestureLongPressCallback? callback, BuildContext context) {
if (callback == null)
return null;
return () {
......@@ -175,5 +167,5 @@ class Feedback {
};
}
static TargetPlatform _platform(BuildContext context) => Theme.of(context).platform;
static TargetPlatform _platform(BuildContext context) => Theme.of(context)!.platform;
}
......@@ -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/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -56,7 +54,7 @@ enum MaterialType {
///
/// * [MaterialType]
/// * [Material]
final Map<MaterialType, BorderRadius> kMaterialEdges = <MaterialType, BorderRadius>{
final Map<MaterialType, BorderRadius?> kMaterialEdges = <MaterialType, BorderRadius?>{
MaterialType.canvas: null,
MaterialType.card: BorderRadius.circular(2.0),
MaterialType.circle: null,
......@@ -69,7 +67,7 @@ final Map<MaterialType, BorderRadius> kMaterialEdges = <MaterialType, BorderRadi
/// Typically obtained via [Material.of].
abstract class MaterialInkController {
/// The color of the material.
Color get color;
Color? get color;
/// The ticker provider used by the controller.
///
......@@ -177,7 +175,7 @@ class Material extends StatefulWidget {
/// [MaterialType.circle]. In both cases, these restrictions are intended to
/// catch likely errors.
const Material({
Key key,
Key? key,
this.type = MaterialType.canvas,
this.elevation = 0.0,
this.color,
......@@ -201,7 +199,7 @@ class Material extends StatefulWidget {
/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.child}
final Widget child;
final Widget? child;
/// The kind of material to show (e.g., card or canvas). This
/// affects the shape of the widget, the roundness of its corners if
......@@ -242,7 +240,7 @@ class Material extends StatefulWidget {
/// composited on top of this color to indicate the elevation.
///
/// By default, the color is derived from the [type] of material.
final Color color;
final Color? color;
/// The color to paint the shadow below the material.
///
......@@ -257,10 +255,10 @@ class Material extends StatefulWidget {
///
/// * [ThemeData.applyElevationOverlayColor], which turns elevation overlay
/// on or off for dark themes.
final Color shadowColor;
final Color? shadowColor;
/// The typographical style to use for text within this material.
final TextStyle textStyle;
final TextStyle? textStyle;
/// Defines the material's shape as well its shadow.
///
......@@ -269,7 +267,7 @@ class Material extends StatefulWidget {
///
/// A shadow is only displayed if the [elevation] is greater than
/// zero.
final ShapeBorder shape;
final ShapeBorder? shape;
/// Whether to paint the [shape] border in front of the [child].
///
......@@ -302,7 +300,7 @@ class Material extends StatefulWidget {
/// If [shape] is non null then the border radius is ignored.
///
/// Must be null if [type] is [MaterialType.circle].
final BorderRadiusGeometry borderRadius;
final BorderRadiusGeometry? borderRadius;
/// The ink controller from the closest instance of this class that
/// encloses the given context.
......@@ -312,9 +310,8 @@ class Material extends StatefulWidget {
/// ```dart
/// MaterialInkController inkController = Material.of(context);
/// ```
static MaterialInkController of(BuildContext context) {
final _RenderInkFeatures result = context.findAncestorRenderObjectOfType<_RenderInkFeatures>();
return result;
static MaterialInkController? of(BuildContext context) {
return context.findAncestorRenderObjectOfType<_RenderInkFeatures>();
}
@override
......@@ -340,9 +337,9 @@ class Material extends StatefulWidget {
class _MaterialState extends State<Material> with TickerProviderStateMixin {
final GlobalKey _inkFeatureRenderer = GlobalKey(debugLabel: 'ink renderer');
Color _getBackgroundColor(BuildContext context) {
final ThemeData theme = Theme.of(context);
Color color = widget.color;
Color? _getBackgroundColor(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
Color? color = widget.color;
if (color == null) {
switch (widget.type) {
case MaterialType.canvas:
......@@ -360,7 +357,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final Color backgroundColor = _getBackgroundColor(context);
final Color? backgroundColor = _getBackgroundColor(context);
assert(
backgroundColor != null || widget.type == MaterialType.transparency,
'If Material type is not MaterialType.transparency, a color must '
......@@ -368,17 +365,17 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
'in the theme (ex. canvasColor != null if type is set to '
'MaterialType.canvas)'
);
Widget contents = widget.child;
Widget? contents = widget.child;
if (contents != null) {
contents = AnimatedDefaultTextStyle(
style: widget.textStyle ?? Theme.of(context).textTheme.bodyText2,
style: widget.textStyle ?? Theme.of(context)!.textTheme.bodyText2!,
duration: widget.animationDuration,
child: contents,
);
}
contents = NotificationListener<LayoutChangedNotification>(
onNotification: (LayoutChangedNotification notification) {
final _RenderInkFeatures renderer = _inkFeatureRenderer.currentContext.findRenderObject() as _RenderInkFeatures;
final _RenderInkFeatures renderer = _inkFeatureRenderer.currentContext!.findRenderObject()! as _RenderInkFeatures;
renderer._didChangeLayout();
return false;
},
......@@ -408,8 +405,8 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
clipBehavior: widget.clipBehavior,
borderRadius: BorderRadius.zero,
elevation: widget.elevation,
color: ElevationOverlay.applyOverlay(context, backgroundColor, widget.elevation),
shadowColor: widget.shadowColor ?? Theme.of(context).shadowColor,
color: ElevationOverlay.applyOverlay(context, backgroundColor!, widget.elevation),
shadowColor: widget.shadowColor ?? Theme.of(context)!.shadowColor,
animateColor: false,
child: contents,
);
......@@ -433,17 +430,17 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
borderOnForeground: widget.borderOnForeground,
clipBehavior: widget.clipBehavior,
elevation: widget.elevation,
color: backgroundColor,
shadowColor: widget.shadowColor ?? Theme.of(context).shadowColor,
color: backgroundColor!,
shadowColor: widget.shadowColor ?? Theme.of(context)!.shadowColor,
child: contents,
);
}
static Widget _transparentInterior({
@required BuildContext context,
@required ShapeBorder shape,
@required Clip clipBehavior,
@required Widget contents,
required BuildContext context,
required ShapeBorder shape,
required Clip clipBehavior,
required Widget contents,
}) {
final _ShapeBorderPaint child = _ShapeBorderPaint(
child: contents,
......@@ -471,9 +468,9 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
// Material class documentation.
ShapeBorder _getShape() {
if (widget.shape != null)
return widget.shape;
return widget.shape!;
if (widget.borderRadius != null)
return RoundedRectangleBorder(borderRadius: widget.borderRadius);
return RoundedRectangleBorder(borderRadius: widget.borderRadius!);
switch (widget.type) {
case MaterialType.canvas:
case MaterialType.transparency:
......@@ -482,21 +479,20 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
case MaterialType.card:
case MaterialType.button:
return RoundedRectangleBorder(
borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type],
borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type]!,
);
case MaterialType.circle:
return const CircleBorder();
}
return const RoundedRectangleBorder();
}
}
class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController {
_RenderInkFeatures({
RenderBox child,
@required this.vsync,
this.absorbHitTest,
RenderBox? child,
required this.vsync,
required this.absorbHitTest,
this.color,
}) : assert(vsync != null),
super(child);
......@@ -511,30 +507,30 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
// The actual painting of this color is done by a Container in the
// MaterialState build method.
@override
Color color;
Color? color;
bool absorbHitTest;
List<InkFeature> _inkFeatures;
List<InkFeature>? _inkFeatures;
@override
void addInkFeature(InkFeature feature) {
assert(!feature._debugDisposed);
assert(feature._controller == this);
_inkFeatures ??= <InkFeature>[];
assert(!_inkFeatures.contains(feature));
_inkFeatures.add(feature);
assert(!_inkFeatures!.contains(feature));
_inkFeatures!.add(feature);
markNeedsPaint();
}
void _removeFeature(InkFeature feature) {
assert(_inkFeatures != null);
_inkFeatures.remove(feature);
_inkFeatures!.remove(feature);
markNeedsPaint();
}
void _didChangeLayout() {
if (_inkFeatures != null && _inkFeatures.isNotEmpty)
if (_inkFeatures != null && _inkFeatures!.isNotEmpty)
markNeedsPaint();
}
......@@ -543,12 +539,12 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
@override
void paint(PaintingContext context, Offset offset) {
if (_inkFeatures != null && _inkFeatures.isNotEmpty) {
if (_inkFeatures != null && _inkFeatures!.isNotEmpty) {
final Canvas canvas = context.canvas;
canvas.save();
canvas.translate(offset.dx, offset.dy);
canvas.clipRect(Offset.zero & size);
for (final InkFeature inkFeature in _inkFeatures)
for (final InkFeature inkFeature in _inkFeatures!)
inkFeature._paint(canvas);
canvas.restore();
}
......@@ -558,17 +554,17 @@ class _RenderInkFeatures extends RenderProxyBox implements MaterialInkController
class _InkFeatures extends SingleChildRenderObjectWidget {
const _InkFeatures({
Key key,
Key? key,
this.color,
@required this.vsync,
@required this.absorbHitTest,
Widget child,
required this.vsync,
required this.absorbHitTest,
Widget? child,
}) : super(key: key, child: child);
// This widget must be owned by a MaterialState, which must be provided as the vsync.
// This relationship must be 1:1 and cannot change for the lifetime of the MaterialState.
final Color color;
final Color? color;
final TickerProvider vsync;
......@@ -599,8 +595,8 @@ class _InkFeatures extends SingleChildRenderObjectWidget {
abstract class InkFeature {
/// Initializes fields for subclasses.
InkFeature({
@required MaterialInkController controller,
@required this.referenceBox,
required MaterialInkController controller,
required this.referenceBox,
this.onRemoved,
}) : assert(controller != null),
assert(referenceBox != null),
......@@ -617,7 +613,7 @@ abstract class InkFeature {
final RenderBox referenceBox;
/// Called when the ink feature is no longer visible on the material.
final VoidCallback onRemoved;
final VoidCallback? onRemoved;
bool _debugDisposed = false;
......@@ -631,7 +627,7 @@ abstract class InkFeature {
}());
_controller._removeFeature(this);
if (onRemoved != null)
onRemoved();
onRemoved!();
}
void _paint(Canvas canvas) {
......@@ -667,16 +663,16 @@ abstract class InkFeature {
/// An interpolation between two [ShapeBorder]s.
///
/// This class specializes the interpolation of [Tween] to use [ShapeBorder.lerp].
class ShapeBorderTween extends Tween<ShapeBorder> {
class ShapeBorderTween extends Tween<ShapeBorder?> {
/// Creates a [ShapeBorder] tween.
///
/// the [begin] and [end] properties may be null; see [ShapeBorder.lerp] for
/// the null handling semantics.
ShapeBorderTween({ShapeBorder begin, ShapeBorder end}) : super(begin: begin, end: end);
ShapeBorderTween({ShapeBorder? begin, ShapeBorder? end}) : super(begin: begin, end: end);
/// Returns the value this tween has at the given animation clock value.
@override
ShapeBorder lerp(double t) {
ShapeBorder? lerp(double t) {
return ShapeBorder.lerp(begin, end, t);
}
}
......@@ -691,16 +687,16 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
/// must not be null. The [elevation] must be specified and greater than or
/// equal to zero.
const _MaterialInterior({
Key key,
@required this.child,
@required this.shape,
Key? key,
required this.child,
required this.shape,
this.borderOnForeground = true,
this.clipBehavior = Clip.none,
@required this.elevation,
@required this.color,
@required this.shadowColor,
required this.elevation,
required this.color,
required this.shadowColor,
Curve curve = Curves.linear,
@required Duration duration,
required Duration duration,
}) : assert(child != null),
assert(shape != null),
assert(clipBehavior != null),
......@@ -757,9 +753,9 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
}
class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior> {
Tween<double> _elevation;
ColorTween _shadowColor;
ShapeBorderTween _border;
Tween<double>? _elevation;
ColorTween? _shadowColor;
ShapeBorderTween? _border;
@override
void forEachTween(TweenVisitor<dynamic> visitor) {
......@@ -782,8 +778,8 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
@override
Widget build(BuildContext context) {
final ShapeBorder shape = _border.evaluate(animation);
final double elevation = _elevation.evaluate(animation);
final ShapeBorder shape = _border!.evaluate(animation!)!;
final double elevation = _elevation!.evaluate(animation!);
return PhysicalShape(
child: _ShapeBorderPaint(
child: widget.child,
......@@ -797,15 +793,15 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
clipBehavior: widget.clipBehavior,
elevation: elevation,
color: ElevationOverlay.applyOverlay(context, widget.color, elevation),
shadowColor: _shadowColor.evaluate(animation),
shadowColor: _shadowColor!.evaluate(animation!)!,
);
}
}
class _ShapeBorderPaint extends StatelessWidget {
const _ShapeBorderPaint({
@required this.child,
@required this.shape,
required this.child,
required this.shape,
this.borderOnForeground = true,
});
......@@ -826,7 +822,7 @@ class _ShapeBorderPaint extends StatelessWidget {
class _ShapeBorderPainter extends CustomPainter {
_ShapeBorderPainter(this.border, this.textDirection);
final ShapeBorder border;
final TextDirection textDirection;
final TextDirection? textDirection;
@override
void paint(Canvas canvas, Size size) {
......
......@@ -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';
......@@ -135,7 +133,7 @@ abstract class MaterialLocalizations {
/// there are, e.g. 'Tab 1 of 2' in United States English.
///
/// `tabIndex` and `tabCount` must be greater than or equal to one.
String tabLabel({ int tabIndex, int tabCount });
String tabLabel({ required int tabIndex, required int tabCount });
/// Title for the [PaginatedDataTable]'s selected row count header.
String selectedRowCountTitle(int selectedRowCount);
......@@ -319,7 +317,7 @@ abstract class MaterialLocalizations {
///
/// See also:
/// * [formatCompactDate], which will convert a [DateTime] into a string in the compact format.
DateTime parseCompactDate(String inputString);
DateTime? parseCompactDate(String? inputString);
/// List of week day names in narrow format, usually 1- or 2-letter
/// abbreviations of full names.
......@@ -505,7 +503,7 @@ abstract class MaterialLocalizations {
/// ```dart
/// tooltip: MaterialLocalizations.of(context).backButtonTooltip,
/// ```
static MaterialLocalizations of(BuildContext context) {
static MaterialLocalizations? of(BuildContext context) {
return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
}
}
......@@ -696,24 +694,28 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
}
@override
DateTime parseCompactDate(String inputString) {
DateTime? parseCompactDate(String? inputString) {
if (inputString == null) {
return null;
}
// Assumes US mm/dd/yyyy format
final List<String> inputParts = inputString.split('/');
if (inputParts.length != 3) {
return null;
}
final int year = int.tryParse(inputParts[2], radix: 10);
final int? year = int.tryParse(inputParts[2], radix: 10);
if (year == null || year < 1) {
return null;
}
final int month = int.tryParse(inputParts[0], radix: 10);
final int? month = int.tryParse(inputParts[0], radix: 10);
if (month == null || month < 1 || month > 12) {
return null;
}
final int day = int.tryParse(inputParts[1], radix: 10);
final int? day = int.tryParse(inputParts[1], radix: 10);
if (day == null || day < 1 || day > _getDaysInMonth(year, month)) {
return null;
}
......@@ -808,7 +810,6 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
case DayPeriod.pm:
return postMeridiemAbbreviation;
}
return null;
}
@override
......@@ -932,7 +933,7 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
String get rowsPerPageTitle => 'Rows per page:';
@override
String tabLabel({ int tabIndex, int tabCount }) {
String tabLabel({ required int tabIndex, required int tabCount }) {
assert(tabIndex >= 1);
assert(tabCount >= 1);
return 'Tab $tabIndex of $tabCount';
......
......@@ -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';
......@@ -85,22 +83,22 @@ class SnackBarAction extends StatefulWidget {
///
/// The [label] and [onPressed] arguments must be non-null.
const SnackBarAction({
Key key,
Key? key,
this.textColor,
this.disabledTextColor,
@required this.label,
@required this.onPressed,
required this.label,
required this.onPressed,
}) : assert(label != null),
assert(onPressed != null),
super(key: key);
/// The button label color. If not provided, defaults to
/// [SnackBarThemeData.actionTextColor].
final Color textColor;
final Color? textColor;
/// The button disabled label color. This color is shown after the
/// [SnackBarAction] is dismissed.
final Color disabledTextColor;
final Color? disabledTextColor;
/// The button label.
final String label;
......@@ -125,13 +123,13 @@ class _SnackBarActionState extends State<SnackBarAction> {
_haveTriggeredAction = true;
});
widget.onPressed();
Scaffold.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
Scaffold.of(context)!.hideCurrentSnackBar(reason: SnackBarClosedReason.action);
}
@override
Widget build(BuildContext context) {
Color resolveForegroundColor(Set<MaterialState> states) {
final SnackBarThemeData snackBarTheme = Theme.of(context).snackBarTheme;
Color? resolveForegroundColor(Set<MaterialState> states) {
final SnackBarThemeData snackBarTheme = Theme.of(context)!.snackBarTheme;
if (states.contains(MaterialState.disabled))
return widget.disabledTextColor ?? snackBarTheme.disabledActionTextColor;
return widget.textColor ?? snackBarTheme.actionTextColor;
......@@ -178,8 +176,8 @@ class SnackBar extends StatefulWidget {
/// The [content] argument must be non-null. The [elevation] must be null or
/// non-negative.
const SnackBar({
Key key,
@required this.content,
Key? key,
required this.content,
this.backgroundColor,
this.elevation,
this.margin,
......@@ -218,7 +216,7 @@ class SnackBar extends StatefulWidget {
/// is not specified it will default to a dark variation of
/// [ColorScheme.surface] for light themes, or [ColorScheme.onSurface] for
/// dark themes.
final Color backgroundColor;
final Color? backgroundColor;
/// The z-coordinate at which to place the snack bar. This controls the size
/// of the shadow below the snack bar.
......@@ -228,7 +226,7 @@ class SnackBar extends StatefulWidget {
/// If this property is null, then [SnackBarThemeData.elevation] of
/// [ThemeData.snackBarTheme] is used, if that is also null, the default value
/// is 6.0.
final double elevation;
final double? elevation;
/// Empty space to surround the snack bar.
///
......@@ -237,7 +235,7 @@ class SnackBar extends StatefulWidget {
///
/// If this property is null, then the default is
/// `EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0)`.
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// The amount of padding to apply to the snack bar's content and optional
/// action.
......@@ -246,7 +244,7 @@ class SnackBar extends StatefulWidget {
/// the presence of an [action]. The start padding is 24 if [behavior] is
/// [SnackBarBehavior.fixed] and 16 if it is [SnackBarBehavior.floating]. If
/// there is no [action], the same padding is added to the end.
final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry? padding;
/// The width of the snack bar.
///
......@@ -256,7 +254,7 @@ class SnackBar extends StatefulWidget {
///
/// If this property is null, then the snack bar will take up the full device
/// width less the margin.
final double width;
final double? width;
/// The shape of the snack bar's [Material].
///
......@@ -268,7 +266,7 @@ class SnackBar extends StatefulWidget {
/// overriding shape is specified, so the [SnackBar] is rectangular. For
/// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a
/// circular corner radius of 4.0.
final ShapeBorder shape;
final ShapeBorder? shape;
/// This defines the behavior and location of the snack bar.
///
......@@ -279,7 +277,7 @@ class SnackBar extends StatefulWidget {
/// If this property is null, then [SnackBarThemeData.behavior] of
/// [ThemeData.snackBarTheme] is used. If that is null, then the default is
/// [SnackBarBehavior.fixed].
final SnackBarBehavior behavior;
final SnackBarBehavior? behavior;
/// (optional) An action that the user can take based on the snack bar.
///
......@@ -287,7 +285,7 @@ class SnackBar extends StatefulWidget {
/// prompted the snackbar. Snack bars can have at most one action.
///
/// The action should not be "dismiss" or "cancel".
final SnackBarAction action;
final SnackBarAction? action;
/// The amount of time the snack bar should be displayed.
///
......@@ -302,15 +300,15 @@ class SnackBar extends StatefulWidget {
final Duration duration;
/// The animation driving the entrance and exit of the snack bar.
final Animation<double> animation;
final Animation<double>? animation;
/// Called the first time that the snackbar is visible within a [Scaffold].
final VoidCallback onVisible;
final VoidCallback? onVisible;
// API for Scaffold.showSnackBar():
/// Creates an animation controller useful for driving a snack bar's entrance and exit animation.
static AnimationController createAnimationController({ @required TickerProvider vsync }) {
static AnimationController createAnimationController({ required TickerProvider vsync }) {
return AnimationController(
duration: _snackBarTransitionDuration,
debugLabel: 'SnackBar',
......@@ -322,7 +320,7 @@ class SnackBar extends StatefulWidget {
///
/// If the original snack bar lacks a key, the newly created snack bar will
/// use the given fallback key.
SnackBar withAnimation(Animation<double> newAnimation, { Key fallbackKey }) {
SnackBar withAnimation(Animation<double> newAnimation, { Key? fallbackKey }) {
return SnackBar(
key: key ?? fallbackKey,
content: content,
......@@ -351,21 +349,21 @@ class _SnackBarState extends State<SnackBar> {
@override
void initState() {
super.initState();
widget.animation.addStatusListener(_onAnimationStatusChanged);
widget.animation!.addStatusListener(_onAnimationStatusChanged);
}
@override
void didUpdateWidget(SnackBar oldWidget) {
if (widget.animation != oldWidget.animation) {
oldWidget.animation.removeStatusListener(_onAnimationStatusChanged);
widget.animation.addStatusListener(_onAnimationStatusChanged);
oldWidget.animation!.removeStatusListener(_onAnimationStatusChanged);
widget.animation!.addStatusListener(_onAnimationStatusChanged);
}
super.didUpdateWidget(oldWidget);
}
@override
void dispose() {
widget.animation.removeStatusListener(_onAnimationStatusChanged);
widget.animation!.removeStatusListener(_onAnimationStatusChanged);
super.dispose();
}
......@@ -377,7 +375,7 @@ class _SnackBarState extends State<SnackBar> {
break;
case AnimationStatus.completed:
if (widget.onVisible != null && !_wasVisible) {
widget.onVisible();
widget.onVisible!();
}
_wasVisible = true;
}
......@@ -385,9 +383,10 @@ class _SnackBarState extends State<SnackBar> {
@override
Widget build(BuildContext context) {
final MediaQueryData mediaQueryData = MediaQuery.of(context);
assert(debugCheckHasMediaQuery(context));
final MediaQueryData mediaQueryData = MediaQuery.of(context)!;
assert(widget.animation != null);
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
final ColorScheme colorScheme = theme.colorScheme;
final SnackBarThemeData snackBarTheme = theme.snackBarTheme;
final bool isThemeDark = theme.brightness == Brightness.dark;
......@@ -422,17 +421,17 @@ class _SnackBarState extends State<SnackBar> {
snackBarTheme: snackBarTheme,
);
final TextStyle contentTextStyle = snackBarTheme.contentTextStyle ?? inverseTheme.textTheme.subtitle1;
final TextStyle? contentTextStyle = snackBarTheme.contentTextStyle ?? inverseTheme.textTheme.subtitle1;
final SnackBarBehavior snackBarBehavior = widget.behavior ?? snackBarTheme.behavior ?? SnackBarBehavior.fixed;
final bool isFloatingSnackBar = snackBarBehavior == SnackBarBehavior.floating;
final double horizontalPadding = isFloatingSnackBar ? 16.0 : 24.0;
final EdgeInsetsGeometry padding = widget.padding
?? EdgeInsetsDirectional.only(start: horizontalPadding, end: widget.action != null ? 0 : horizontalPadding);
final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation, curve: _snackBarHeightCurve);
final CurvedAnimation fadeInAnimation = CurvedAnimation(parent: widget.animation, curve: _snackBarFadeInCurve);
final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarHeightCurve);
final CurvedAnimation fadeInAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarFadeInCurve);
final CurvedAnimation fadeOutAnimation = CurvedAnimation(
parent: widget.animation,
parent: widget.animation!,
curve: _snackBarFadeOutCurve,
reverseCurve: const Threshold(0.0),
);
......@@ -474,7 +473,7 @@ class _SnackBarState extends State<SnackBar> {
final double elevation = widget.elevation ?? snackBarTheme.elevation ?? 6.0;
final Color backgroundColor = widget.backgroundColor ?? snackBarTheme.backgroundColor ?? inverseTheme.backgroundColor;
final ShapeBorder shape = widget.shape
final ShapeBorder? shape = widget.shape
?? snackBarTheme.shape
?? (isFloatingSnackBar ? RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)) : null);
......@@ -526,14 +525,14 @@ class _SnackBarState extends State<SnackBar> {
container: true,
liveRegion: true,
onDismiss: () {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss);
Scaffold.of(context)!.removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss);
},
child: Dismissible(
key: const Key('dismissible'),
direction: DismissDirection.down,
resizeDuration: null,
onDismissed: (DismissDirection direction) {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
Scaffold.of(context)!.removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
},
child: snackBar,
),
......@@ -550,7 +549,7 @@ class _SnackBarState extends State<SnackBar> {
} else {
snackBarTransition = AnimatedBuilder(
animation: heightAnimation,
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
return Align(
alignment: AlignmentDirectional.topStart,
heightFactor: heightAnimation.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 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -67,30 +65,30 @@ class SnackBarThemeData with Diagnosticable {
/// Default value for [SnackBar.backgroundColor].
///
/// If null, [SnackBar] defaults to dark grey: `Color(0xFF323232)`.
final Color backgroundColor;
final Color? backgroundColor;
/// Default value for [SnackBarAction.textColor].
///
/// If null, [SnackBarAction] defaults to [ColorScheme.secondary] of
/// [ThemeData.colorScheme] .
final Color actionTextColor;
final Color? actionTextColor;
/// Default value for [SnackBarAction.disabledTextColor].
///
/// If null, [SnackBarAction] defaults to [ColorScheme.onSurface] with its
/// opacity set to 0.30 if the [Theme]'s brightness is [Brightness.dark], 0.38
/// otherwise.
final Color disabledActionTextColor;
final Color? disabledActionTextColor;
/// Used to configure the [DefaultTextStyle] for the [SnackBar.content] widget.
///
/// If null, [SnackBar] defines its default.
final TextStyle contentTextStyle;
final TextStyle? contentTextStyle;
/// Default value for [SnackBar.elevation].
///
/// If null, [SnackBar] uses a default of 6.0.
final double elevation;
final double? elevation;
/// Default value for [SnackBar.shape].
///
......@@ -99,23 +97,23 @@ class SnackBarThemeData with Diagnosticable {
/// specified, so the [SnackBar] is rectangular. For
/// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a
/// circular corner radius of 4.0.
final ShapeBorder shape;
final ShapeBorder? shape;
/// Default value for [SnackBar.behavior].
///
/// If null, [SnackBar] will default to [SnackBarBehavior.fixed].
final SnackBarBehavior behavior;
final SnackBarBehavior? behavior;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
SnackBarThemeData copyWith({
Color backgroundColor,
Color actionTextColor,
Color disabledActionTextColor,
TextStyle contentTextStyle,
double elevation,
ShapeBorder shape,
SnackBarBehavior behavior,
Color? backgroundColor,
Color? actionTextColor,
Color? disabledActionTextColor,
TextStyle? contentTextStyle,
double? elevation,
ShapeBorder? shape,
SnackBarBehavior? behavior,
}) {
return SnackBarThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -133,7 +131,7 @@ class SnackBarThemeData with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static SnackBarThemeData lerp(SnackBarThemeData a, SnackBarThemeData b, double t) {
static SnackBarThemeData lerp(SnackBarThemeData? a, SnackBarThemeData? b, double t) {
assert(t != null);
return SnackBarThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
......@@ -142,7 +140,7 @@ class SnackBarThemeData with Diagnosticable {
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
behavior: t < 0.5 ? a.behavior : b.behavior,
behavior: t < 0.5 ? a?.behavior : b?.behavior,
);
}
......
......@@ -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/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
......@@ -40,10 +38,10 @@ class Theme extends StatelessWidget {
///
/// The [data] and [child] arguments must not be null.
const Theme({
Key key,
@required this.data,
Key? key,
required this.data,
this.isMaterialAppTheme = false,
@required this.child,
required this.child,
}) : assert(child != null),
assert(data != null),
super(key: key);
......@@ -126,17 +124,17 @@ class Theme extends StatelessWidget {
/// );
/// }
/// ```
static ThemeData of(BuildContext context, { bool shadowThemeOnly = false }) {
final _InheritedTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
static ThemeData? of(BuildContext context, { bool shadowThemeOnly = false }) {
final _InheritedTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
if (shadowThemeOnly) {
if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme)
return null;
return inheritedTheme.theme.data;
}
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final MaterialLocalizations? localizations = MaterialLocalizations.of(context);
final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike;
final ThemeData theme = inheritedTheme?.theme?.data ?? _kFallbackTheme;
final ThemeData theme = inheritedTheme?.theme.data ?? _kFallbackTheme;
return ThemeData.localize(theme, theme.typography.geometryThemeFor(category));
}
......@@ -168,9 +166,9 @@ class Theme extends StatelessWidget {
class _InheritedTheme extends InheritedTheme {
const _InheritedTheme({
Key key,
@required this.theme,
@required Widget child,
Key? key,
required this.theme,
required Widget child,
}) : assert(theme != null),
super(key: key, child: child);
......@@ -178,7 +176,7 @@ class _InheritedTheme extends InheritedTheme {
@override
Widget wrap(BuildContext context, Widget child) {
final _InheritedTheme ancestorTheme = context.findAncestorWidgetOfExactType<_InheritedTheme>();
final _InheritedTheme? ancestorTheme = context.findAncestorWidgetOfExactType<_InheritedTheme>();
return identical(this, ancestorTheme) ? child : Theme(data: theme.data, child: child);
}
......@@ -198,10 +196,10 @@ class ThemeDataTween extends Tween<ThemeData> {
/// The [begin] and [end] properties must be non-null before the tween is
/// first used, but the arguments can be null if the values are going to be
/// filled in later.
ThemeDataTween({ ThemeData begin, ThemeData end }) : super(begin: begin, end: end);
ThemeDataTween({ ThemeData? begin, ThemeData? end }) : super(begin: begin, end: end);
@override
ThemeData lerp(double t) => ThemeData.lerp(begin, end, t);
ThemeData lerp(double t) => ThemeData.lerp(begin!, end!, t);
}
/// Animated version of [Theme] which automatically transitions the colors,
......@@ -224,13 +222,13 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget {
/// By default, the theme transition uses a linear curve. The [data] and
/// [child] arguments must not be null.
const AnimatedTheme({
Key key,
@required this.data,
Key? key,
required this.data,
this.isMaterialAppTheme = false,
Curve curve = Curves.linear,
Duration duration = kThemeAnimationDuration,
VoidCallback onEnd,
@required this.child,
VoidCallback? onEnd,
required this.child,
}) : assert(child != null),
assert(data != null),
super(key: key, curve: curve, duration: duration, onEnd: onEnd);
......@@ -251,7 +249,7 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget {
}
class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> {
ThemeDataTween _data;
ThemeDataTween? _data;
@override
void forEachTween(TweenVisitor<dynamic> visitor) {
......@@ -265,7 +263,7 @@ class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> {
return Theme(
isMaterialAppTheme: widget.isMaterialAppTheme,
child: widget.child,
data: _data.evaluate(animation),
data: _data!.evaluate(animation!),
);
}
......
......@@ -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, hashList, lerpDouble;
import 'package:flutter/cupertino.dart';
......@@ -211,118 +209,118 @@ class ThemeData with Diagnosticable {
/// * [ThemeData.light], which creates a light blue theme.
/// * [ThemeData.dark], which creates dark theme with a teal secondary [ColorScheme] color.
factory ThemeData({
Brightness brightness,
VisualDensity visualDensity,
MaterialColor primarySwatch,
Color primaryColor,
Brightness primaryColorBrightness,
Color primaryColorLight,
Color primaryColorDark,
Color accentColor,
Brightness accentColorBrightness,
Color canvasColor,
Color shadowColor,
Color scaffoldBackgroundColor,
Color bottomAppBarColor,
Color cardColor,
Color dividerColor,
Color focusColor,
Color hoverColor,
Color highlightColor,
Color splashColor,
InteractiveInkFeatureFactory splashFactory,
Color selectedRowColor,
Color unselectedWidgetColor,
Color disabledColor,
Color buttonColor,
ButtonThemeData buttonTheme,
ToggleButtonsThemeData toggleButtonsTheme,
Color secondaryHeaderColor,
Brightness? brightness,
VisualDensity? visualDensity,
MaterialColor? primarySwatch,
Color? primaryColor,
Brightness? primaryColorBrightness,
Color? primaryColorLight,
Color? primaryColorDark,
Color? accentColor,
Brightness? accentColorBrightness,
Color? canvasColor,
Color? shadowColor,
Color? scaffoldBackgroundColor,
Color? bottomAppBarColor,
Color? cardColor,
Color? dividerColor,
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? splashColor,
InteractiveInkFeatureFactory? splashFactory,
Color? selectedRowColor,
Color? unselectedWidgetColor,
Color? disabledColor,
Color? buttonColor,
ButtonThemeData? buttonTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
Color? secondaryHeaderColor,
@Deprecated(
'Use TextSelectionThemeData.selectionColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionColor,
Color? textSelectionColor,
@Deprecated(
'Use TextSelectionThemeData.cursorColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color cursorColor,
Color? cursorColor,
@Deprecated(
'Use TextSelectionThemeData.selectionHandleColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionHandleColor,
Color backgroundColor,
Color dialogBackgroundColor,
Color indicatorColor,
Color hintColor,
Color errorColor,
Color toggleableActiveColor,
String fontFamily,
TextTheme textTheme,
TextTheme primaryTextTheme,
TextTheme accentTextTheme,
InputDecorationTheme inputDecorationTheme,
IconThemeData iconTheme,
IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
SliderThemeData sliderTheme,
TabBarTheme tabBarTheme,
TooltipThemeData tooltipTheme,
CardTheme cardTheme,
ChipThemeData chipTheme,
TargetPlatform platform,
MaterialTapTargetSize materialTapTargetSize,
bool applyElevationOverlayColor,
PageTransitionsTheme pageTransitionsTheme,
AppBarTheme appBarTheme,
BottomAppBarTheme bottomAppBarTheme,
ColorScheme colorScheme,
DialogTheme dialogTheme,
FloatingActionButtonThemeData floatingActionButtonTheme,
NavigationRailThemeData navigationRailTheme,
Typography typography,
NoDefaultCupertinoThemeData cupertinoOverrideTheme,
SnackBarThemeData snackBarTheme,
BottomSheetThemeData bottomSheetTheme,
PopupMenuThemeData popupMenuTheme,
MaterialBannerThemeData bannerTheme,
DividerThemeData dividerTheme,
ButtonBarThemeData buttonBarTheme,
BottomNavigationBarThemeData bottomNavigationBarTheme,
TimePickerThemeData timePickerTheme,
TextButtonThemeData textButtonTheme,
ElevatedButtonThemeData elevatedButtonTheme,
OutlinedButtonThemeData outlinedButtonTheme,
TextSelectionThemeData textSelectionTheme,
DataTableThemeData dataTableTheme,
bool fixTextFieldOutlineLabel,
Color? textSelectionHandleColor,
Color? backgroundColor,
Color? dialogBackgroundColor,
Color? indicatorColor,
Color? hintColor,
Color? errorColor,
Color? toggleableActiveColor,
String? fontFamily,
TextTheme? textTheme,
TextTheme? primaryTextTheme,
TextTheme? accentTextTheme,
InputDecorationTheme? inputDecorationTheme,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
IconThemeData? accentIconTheme,
SliderThemeData? sliderTheme,
TabBarTheme? tabBarTheme,
TooltipThemeData? tooltipTheme,
CardTheme? cardTheme,
ChipThemeData? chipTheme,
TargetPlatform? platform,
MaterialTapTargetSize? materialTapTargetSize,
bool? applyElevationOverlayColor,
PageTransitionsTheme? pageTransitionsTheme,
AppBarTheme? appBarTheme,
BottomAppBarTheme? bottomAppBarTheme,
ColorScheme? colorScheme,
DialogTheme? dialogTheme,
FloatingActionButtonThemeData? floatingActionButtonTheme,
NavigationRailThemeData? navigationRailTheme,
Typography? typography,
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
SnackBarThemeData? snackBarTheme,
BottomSheetThemeData? bottomSheetTheme,
PopupMenuThemeData? popupMenuTheme,
MaterialBannerThemeData? bannerTheme,
DividerThemeData? dividerTheme,
ButtonBarThemeData? buttonBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
TimePickerThemeData? timePickerTheme,
TextButtonThemeData? textButtonTheme,
ElevatedButtonThemeData? elevatedButtonTheme,
OutlinedButtonThemeData? outlinedButtonTheme,
TextSelectionThemeData? textSelectionTheme,
DataTableThemeData? dataTableTheme,
bool? fixTextFieldOutlineLabel,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
bool useTextSelectionTheme,
bool? useTextSelectionTheme,
}) {
assert(colorScheme?.brightness == null || brightness == null || colorScheme.brightness == brightness);
assert(colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness);
final Brightness _brightness = brightness ?? colorScheme?.brightness ?? Brightness.light;
final bool isDark = _brightness == Brightness.dark;
visualDensity ??= VisualDensity.adaptivePlatformDensity;
primarySwatch ??= Colors.blue;
primaryColor ??= isDark ? Colors.grey[900] : primarySwatch;
primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch;
primaryColorBrightness ??= estimateBrightnessForColor(primaryColor);
primaryColorLight ??= isDark ? Colors.grey[500] : primarySwatch[100];
primaryColorDark ??= isDark ? Colors.black : primarySwatch[700];
primaryColorLight ??= isDark ? Colors.grey[500]! : primarySwatch[100]!;
primaryColorDark ??= isDark ? Colors.black : primarySwatch[700]!;
final bool primaryIsDark = primaryColorBrightness == Brightness.dark;
toggleableActiveColor ??= isDark ? Colors.tealAccent[200] : (accentColor ?? primarySwatch[600]);
accentColor ??= isDark ? Colors.tealAccent[200] : primarySwatch[500];
toggleableActiveColor ??= isDark ? Colors.tealAccent[200]! : (accentColor ?? primarySwatch[600]!);
accentColor ??= isDark ? Colors.tealAccent[200]! : primarySwatch[500]!;
accentColorBrightness ??= estimateBrightnessForColor(accentColor);
final bool accentIsDark = accentColorBrightness == Brightness.dark;
canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50];
canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!;
shadowColor ??= Colors.black;
scaffoldBackgroundColor ??= canvasColor;
bottomAppBarColor ??= isDark ? Colors.grey[800] : Colors.white;
cardColor ??= isDark ? Colors.grey[800] : Colors.white;
bottomAppBarColor ??= isDark ? Colors.grey[800]! : Colors.white;
cardColor ??= isDark ? Colors.grey[800]! : Colors.white;
dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);
// Create a ColorScheme that is backwards compatible as possible
......@@ -338,18 +336,18 @@ class ThemeData with Diagnosticable {
);
splashFactory ??= InkSplash.splashFactory;
selectedRowColor ??= Colors.grey[100];
selectedRowColor ??= Colors.grey[100]!;
unselectedWidgetColor ??= isDark ? Colors.white70 : Colors.black54;
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess.
secondaryHeaderColor ??= isDark ? Colors.grey[700] : primarySwatch[50];
textSelectionColor ??= isDark ? accentColor : primarySwatch[200];
secondaryHeaderColor ??= isDark ? Colors.grey[700]! : primarySwatch[50]!;
textSelectionColor ??= isDark ? accentColor : primarySwatch[200]!;
cursorColor = cursorColor ?? const Color.fromRGBO(66, 133, 244, 1.0);
textSelectionHandleColor ??= isDark ? Colors.tealAccent[400] : primarySwatch[300];
backgroundColor ??= isDark ? Colors.grey[700] : primarySwatch[200];
dialogBackgroundColor ??= isDark ? Colors.grey[800] : Colors.white;
textSelectionHandleColor ??= isDark ? Colors.tealAccent[400]! : primarySwatch[300]!;
backgroundColor ??= isDark ? Colors.grey[700]! : primarySwatch[200]!;
dialogBackgroundColor ??= isDark ? Colors.grey[800]! : Colors.white;
indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor;
hintColor ??= isDark ? Colors.white60 : Colors.black.withOpacity(0.6);
errorColor ??= Colors.red[700];
errorColor ??= Colors.red[700]!;
inputDecorationTheme ??= const InputDecorationTheme();
pageTransitionsTheme ??= const PageTransitionsTheme();
primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black);
......@@ -384,7 +382,7 @@ class ThemeData with Diagnosticable {
// Used as the default color (fill color) for RaisedButtons. Computing the
// default for ButtonThemeData for the sake of backwards compatibility.
buttonColor ??= isDark ? primarySwatch[600] : Colors.grey[300];
buttonColor ??= isDark ? primarySwatch[600]! : Colors.grey[300]!;
focusColor ??= isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.12);
hoverColor ??= isDark ? Colors.white.withOpacity(0.04) : Colors.black.withOpacity(0.04);
buttonTheme ??= ButtonThemeData(
......@@ -411,7 +409,7 @@ class ThemeData with Diagnosticable {
chipTheme ??= ChipThemeData.fromDefaults(
secondaryColor: primaryColor,
brightness: colorScheme.brightness,
labelStyle: textTheme.bodyText1,
labelStyle: textTheme.bodyText1!,
);
dialogTheme ??= const DialogTheme();
floatingActionButtonTheme ??= const FloatingActionButtonThemeData();
......@@ -522,79 +520,79 @@ class ThemeData with Diagnosticable {
// Warning: make sure these properties are in the exact same order as in
// operator == and in the hashValues method and in the order of fields
// in this class, and in the lerp() method.
@required this.visualDensity,
@required this.primaryColor,
@required this.primaryColorBrightness,
@required this.primaryColorLight,
@required this.primaryColorDark,
@required this.canvasColor,
@required this.shadowColor,
@required this.accentColor,
@required this.accentColorBrightness,
@required this.scaffoldBackgroundColor,
@required this.bottomAppBarColor,
@required this.cardColor,
@required this.dividerColor,
@required this.focusColor,
@required this.hoverColor,
@required this.highlightColor,
@required this.splashColor,
@required this.splashFactory,
@required this.selectedRowColor,
@required this.unselectedWidgetColor,
@required this.disabledColor,
@required this.buttonTheme,
@required this.buttonColor,
@required this.toggleButtonsTheme,
@required this.secondaryHeaderColor,
@required this.textSelectionColor,
@required this.cursorColor,
@required this.textSelectionHandleColor,
@required this.backgroundColor,
@required this.dialogBackgroundColor,
@required this.indicatorColor,
@required this.hintColor,
@required this.errorColor,
@required this.toggleableActiveColor,
@required this.textTheme,
@required this.primaryTextTheme,
@required this.accentTextTheme,
@required this.inputDecorationTheme,
@required this.iconTheme,
@required this.primaryIconTheme,
@required this.accentIconTheme,
@required this.sliderTheme,
@required this.tabBarTheme,
@required this.tooltipTheme,
@required this.cardTheme,
@required this.chipTheme,
@required this.platform,
@required this.materialTapTargetSize,
@required this.applyElevationOverlayColor,
@required this.pageTransitionsTheme,
@required this.appBarTheme,
@required this.bottomAppBarTheme,
@required this.colorScheme,
@required this.dialogTheme,
@required this.floatingActionButtonTheme,
@required this.navigationRailTheme,
@required this.typography,
@required this.cupertinoOverrideTheme,
@required this.snackBarTheme,
@required this.bottomSheetTheme,
@required this.popupMenuTheme,
@required this.bannerTheme,
@required this.dividerTheme,
@required this.buttonBarTheme,
@required this.bottomNavigationBarTheme,
@required this.timePickerTheme,
@required this.textButtonTheme,
@required this.elevatedButtonTheme,
@required this.outlinedButtonTheme,
@required this.textSelectionTheme,
@required this.dataTableTheme,
@required this.fixTextFieldOutlineLabel,
@required this.useTextSelectionTheme,
required this.visualDensity,
required this.primaryColor,
required this.primaryColorBrightness,
required this.primaryColorLight,
required this.primaryColorDark,
required this.canvasColor,
required this.shadowColor,
required this.accentColor,
required this.accentColorBrightness,
required this.scaffoldBackgroundColor,
required this.bottomAppBarColor,
required this.cardColor,
required this.dividerColor,
required this.focusColor,
required this.hoverColor,
required this.highlightColor,
required this.splashColor,
required this.splashFactory,
required this.selectedRowColor,
required this.unselectedWidgetColor,
required this.disabledColor,
required this.buttonTheme,
required this.buttonColor,
required this.toggleButtonsTheme,
required this.secondaryHeaderColor,
required this.textSelectionColor,
required this.cursorColor,
required this.textSelectionHandleColor,
required this.backgroundColor,
required this.dialogBackgroundColor,
required this.indicatorColor,
required this.hintColor,
required this.errorColor,
required this.toggleableActiveColor,
required this.textTheme,
required this.primaryTextTheme,
required this.accentTextTheme,
required this.inputDecorationTheme,
required this.iconTheme,
required this.primaryIconTheme,
required this.accentIconTheme,
required this.sliderTheme,
required this.tabBarTheme,
required this.tooltipTheme,
required this.cardTheme,
required this.chipTheme,
required this.platform,
required this.materialTapTargetSize,
required this.applyElevationOverlayColor,
required this.pageTransitionsTheme,
required this.appBarTheme,
required this.bottomAppBarTheme,
required this.colorScheme,
required this.dialogTheme,
required this.floatingActionButtonTheme,
required this.navigationRailTheme,
required this.typography,
required this.cupertinoOverrideTheme,
required this.snackBarTheme,
required this.bottomSheetTheme,
required this.popupMenuTheme,
required this.bannerTheme,
required this.dividerTheme,
required this.buttonBarTheme,
required this.bottomNavigationBarTheme,
required this.timePickerTheme,
required this.textButtonTheme,
required this.elevatedButtonTheme,
required this.outlinedButtonTheme,
required this.textSelectionTheme,
required this.dataTableTheme,
required this.fixTextFieldOutlineLabel,
required this.useTextSelectionTheme,
}) : assert(visualDensity != null),
assert(primaryColor != null),
assert(primaryColorBrightness != null),
......@@ -695,8 +693,8 @@ class ThemeData with Diagnosticable {
/// See <https://material.io/design/color/> for
/// more discussion on how to pick the right colors.
factory ThemeData.from({
@required ColorScheme colorScheme,
TextTheme textTheme,
required ColorScheme colorScheme,
TextTheme? textTheme,
}) {
assert(colorScheme != null);
......@@ -1110,7 +1108,7 @@ class ThemeData with Diagnosticable {
///
/// This cascading effect for individual attributes of the [CupertinoThemeData]
/// can be overridden using attributes of this [cupertinoOverrideTheme].
final NoDefaultCupertinoThemeData cupertinoOverrideTheme;
final NoDefaultCupertinoThemeData? cupertinoOverrideTheme;
/// A theme for customizing the color, elevation, and shape of a bottom sheet.
final BottomSheetThemeData bottomSheetTheme;
......@@ -1181,96 +1179,96 @@ class ThemeData with Diagnosticable {
///
/// The [brightness] value is applied to the [colorScheme].
ThemeData copyWith({
Brightness brightness,
VisualDensity visualDensity,
Color primaryColor,
Brightness primaryColorBrightness,
Color primaryColorLight,
Color primaryColorDark,
Color accentColor,
Brightness accentColorBrightness,
Color canvasColor,
Color shadowColor,
Color scaffoldBackgroundColor,
Color bottomAppBarColor,
Color cardColor,
Color dividerColor,
Color focusColor,
Color hoverColor,
Color highlightColor,
Color splashColor,
InteractiveInkFeatureFactory splashFactory,
Color selectedRowColor,
Color unselectedWidgetColor,
Color disabledColor,
ButtonThemeData buttonTheme,
ToggleButtonsThemeData toggleButtonsTheme,
Color buttonColor,
Color secondaryHeaderColor,
Brightness? brightness,
VisualDensity? visualDensity,
Color? primaryColor,
Brightness? primaryColorBrightness,
Color? primaryColorLight,
Color? primaryColorDark,
Color? accentColor,
Brightness? accentColorBrightness,
Color? canvasColor,
Color? shadowColor,
Color? scaffoldBackgroundColor,
Color? bottomAppBarColor,
Color? cardColor,
Color? dividerColor,
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? splashColor,
InteractiveInkFeatureFactory? splashFactory,
Color? selectedRowColor,
Color? unselectedWidgetColor,
Color? disabledColor,
ButtonThemeData? buttonTheme,
ToggleButtonsThemeData? toggleButtonsTheme,
Color? buttonColor,
Color? secondaryHeaderColor,
@Deprecated(
'Use TextSelectionThemeData.selectionColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionColor,
Color? textSelectionColor,
@Deprecated(
'Use TextSelectionThemeData.cursorColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color cursorColor,
Color? cursorColor,
@Deprecated(
'Use TextSelectionThemeData.selectionHandleColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionHandleColor,
Color backgroundColor,
Color dialogBackgroundColor,
Color indicatorColor,
Color hintColor,
Color errorColor,
Color toggleableActiveColor,
TextTheme textTheme,
TextTheme primaryTextTheme,
TextTheme accentTextTheme,
InputDecorationTheme inputDecorationTheme,
IconThemeData iconTheme,
IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
SliderThemeData sliderTheme,
TabBarTheme tabBarTheme,
TooltipThemeData tooltipTheme,
CardTheme cardTheme,
ChipThemeData chipTheme,
TargetPlatform platform,
MaterialTapTargetSize materialTapTargetSize,
bool applyElevationOverlayColor,
PageTransitionsTheme pageTransitionsTheme,
AppBarTheme appBarTheme,
BottomAppBarTheme bottomAppBarTheme,
ColorScheme colorScheme,
DialogTheme dialogTheme,
FloatingActionButtonThemeData floatingActionButtonTheme,
NavigationRailThemeData navigationRailTheme,
Typography typography,
NoDefaultCupertinoThemeData cupertinoOverrideTheme,
SnackBarThemeData snackBarTheme,
BottomSheetThemeData bottomSheetTheme,
PopupMenuThemeData popupMenuTheme,
MaterialBannerThemeData bannerTheme,
DividerThemeData dividerTheme,
ButtonBarThemeData buttonBarTheme,
BottomNavigationBarThemeData bottomNavigationBarTheme,
TimePickerThemeData timePickerTheme,
TextButtonThemeData textButtonTheme,
ElevatedButtonThemeData elevatedButtonTheme,
OutlinedButtonThemeData outlinedButtonTheme,
TextSelectionThemeData textSelectionTheme,
DataTableThemeData dataTableTheme,
bool fixTextFieldOutlineLabel,
Color? textSelectionHandleColor,
Color? backgroundColor,
Color? dialogBackgroundColor,
Color? indicatorColor,
Color? hintColor,
Color? errorColor,
Color? toggleableActiveColor,
TextTheme? textTheme,
TextTheme? primaryTextTheme,
TextTheme? accentTextTheme,
InputDecorationTheme? inputDecorationTheme,
IconThemeData? iconTheme,
IconThemeData? primaryIconTheme,
IconThemeData? accentIconTheme,
SliderThemeData? sliderTheme,
TabBarTheme? tabBarTheme,
TooltipThemeData? tooltipTheme,
CardTheme? cardTheme,
ChipThemeData? chipTheme,
TargetPlatform? platform,
MaterialTapTargetSize? materialTapTargetSize,
bool? applyElevationOverlayColor,
PageTransitionsTheme? pageTransitionsTheme,
AppBarTheme? appBarTheme,
BottomAppBarTheme? bottomAppBarTheme,
ColorScheme? colorScheme,
DialogTheme? dialogTheme,
FloatingActionButtonThemeData? floatingActionButtonTheme,
NavigationRailThemeData? navigationRailTheme,
Typography? typography,
NoDefaultCupertinoThemeData? cupertinoOverrideTheme,
SnackBarThemeData? snackBarTheme,
BottomSheetThemeData? bottomSheetTheme,
PopupMenuThemeData? popupMenuTheme,
MaterialBannerThemeData? bannerTheme,
DividerThemeData? dividerTheme,
ButtonBarThemeData? buttonBarTheme,
BottomNavigationBarThemeData? bottomNavigationBarTheme,
TimePickerThemeData? timePickerTheme,
TextButtonThemeData? textButtonTheme,
ElevatedButtonThemeData? elevatedButtonTheme,
OutlinedButtonThemeData? outlinedButtonTheme,
TextSelectionThemeData? textSelectionTheme,
DataTableThemeData? dataTableTheme,
bool? fixTextFieldOutlineLabel,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
bool useTextSelectionTheme,
bool? useTextSelectionTheme,
}) {
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
return ThemeData.raw(
......@@ -1429,39 +1427,39 @@ class ThemeData with Diagnosticable {
// the class and in the lerp() method.
return ThemeData.raw(
visualDensity: VisualDensity.lerp(a.visualDensity, b.visualDensity, t),
primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t),
primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t)!,
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t),
primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t),
canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t),
shadowColor: Color.lerp(a.shadowColor, b.shadowColor, t),
accentColor: Color.lerp(a.accentColor, b.accentColor, t),
primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t)!,
primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t)!,
canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!,
shadowColor: Color.lerp(a.shadowColor, b.shadowColor, t)!,
accentColor: Color.lerp(a.accentColor, b.accentColor, t)!,
accentColorBrightness: t < 0.5 ? a.accentColorBrightness : b.accentColorBrightness,
scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t),
bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t),
cardColor: Color.lerp(a.cardColor, b.cardColor, t),
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t),
focusColor: Color.lerp(a.focusColor, b.focusColor, t),
hoverColor: Color.lerp(a.hoverColor, b.hoverColor, t),
highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t),
splashColor: Color.lerp(a.splashColor, b.splashColor, t),
scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t)!,
bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t)!,
cardColor: Color.lerp(a.cardColor, b.cardColor, t)!,
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t)!,
focusColor: Color.lerp(a.focusColor, b.focusColor, t)!,
hoverColor: Color.lerp(a.hoverColor, b.hoverColor, t)!,
highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t)!,
splashColor: Color.lerp(a.splashColor, b.splashColor, t)!,
splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory,
selectedRowColor: Color.lerp(a.selectedRowColor, b.selectedRowColor, t),
unselectedWidgetColor: Color.lerp(a.unselectedWidgetColor, b.unselectedWidgetColor, t),
disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t),
selectedRowColor: Color.lerp(a.selectedRowColor, b.selectedRowColor, t)!,
unselectedWidgetColor: Color.lerp(a.unselectedWidgetColor, b.unselectedWidgetColor, t)!,
disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t)!,
buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme,
toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t),
buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t),
secondaryHeaderColor: Color.lerp(a.secondaryHeaderColor, b.secondaryHeaderColor, t),
textSelectionColor: Color.lerp(a.textSelectionColor, b.textSelectionColor, t),
cursorColor: Color.lerp(a.cursorColor, b.cursorColor, t),
textSelectionHandleColor: Color.lerp(a.textSelectionHandleColor, b.textSelectionHandleColor, t),
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t),
dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t),
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t),
hintColor: Color.lerp(a.hintColor, b.hintColor, t),
errorColor: Color.lerp(a.errorColor, b.errorColor, t),
toggleableActiveColor: Color.lerp(a.toggleableActiveColor, b.toggleableActiveColor, t),
buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t)!,
secondaryHeaderColor: Color.lerp(a.secondaryHeaderColor, b.secondaryHeaderColor, t)!,
textSelectionColor: Color.lerp(a.textSelectionColor, b.textSelectionColor, t)!,
cursorColor: Color.lerp(a.cursorColor, b.cursorColor, t)!,
textSelectionHandleColor: Color.lerp(a.textSelectionHandleColor, b.textSelectionHandleColor, t)!,
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t)!,
dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!,
indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t)!,
hintColor: Color.lerp(a.hintColor, b.hintColor, t)!,
errorColor: Color.lerp(a.errorColor, b.errorColor, t)!,
toggleableActiveColor: Color.lerp(a.toggleableActiveColor, b.toggleableActiveColor, t)!,
textTheme: TextTheme.lerp(a.textTheme, b.textTheme, t),
primaryTextTheme: TextTheme.lerp(a.primaryTextTheme, b.primaryTextTheme, t),
accentTextTheme: TextTheme.lerp(a.accentTextTheme, b.accentTextTheme, t),
......@@ -1471,9 +1469,9 @@ class ThemeData with Diagnosticable {
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
sliderTheme: SliderThemeData.lerp(a.sliderTheme, b.sliderTheme, t),
tabBarTheme: TabBarTheme.lerp(a.tabBarTheme, b.tabBarTheme, t),
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t),
tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
cardTheme: CardTheme.lerp(a.cardTheme, b.cardTheme, t),
chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t),
chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t)!,
platform: t < 0.5 ? a.platform : b.platform,
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
applyElevationOverlayColor: t < 0.5 ? a.applyElevationOverlayColor : b.applyElevationOverlayColor,
......@@ -1482,20 +1480,20 @@ class ThemeData with Diagnosticable {
bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
dialogTheme: DialogTheme.lerp(a.dialogTheme, b.dialogTheme, t),
floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme, b.floatingActionButtonTheme, t),
floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme, b.floatingActionButtonTheme, t)!,
navigationRailTheme: NavigationRailThemeData.lerp(a.navigationRailTheme, b.navigationRailTheme, t),
typography: Typography.lerp(a.typography, b.typography, t),
cupertinoOverrideTheme: t < 0.5 ? a.cupertinoOverrideTheme : b.cupertinoOverrideTheme,
snackBarTheme: SnackBarThemeData.lerp(a.snackBarTheme, b.snackBarTheme, t),
bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t),
bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t)!,
popupMenuTheme: PopupMenuThemeData.lerp(a.popupMenuTheme, b.popupMenuTheme, t),
bannerTheme: MaterialBannerThemeData.lerp(a.bannerTheme, b.bannerTheme, t),
dividerTheme: DividerThemeData.lerp(a.dividerTheme, b.dividerTheme, t),
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t)!,
bottomNavigationBarTheme: BottomNavigationBarThemeData.lerp(a.bottomNavigationBarTheme, b.bottomNavigationBarTheme, t),
timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t),
textButtonTheme: TextButtonThemeData.lerp(a.textButtonTheme, b.textButtonTheme, t),
elevatedButtonTheme: ElevatedButtonThemeData.lerp(a.elevatedButtonTheme, b.elevatedButtonTheme, t),
elevatedButtonTheme: ElevatedButtonThemeData.lerp(a.elevatedButtonTheme, b.elevatedButtonTheme, t)!,
outlinedButtonTheme: OutlinedButtonThemeData.lerp(a.outlinedButtonTheme, b.outlinedButtonTheme, t),
textSelectionTheme: TextSelectionThemeData .lerp(a.textSelectionTheme, b.textSelectionTheme, t),
dataTableTheme: DataTableThemeData.lerp(a.dataTableTheme, b.dataTableTheme, t),
......@@ -1590,7 +1588,7 @@ class ThemeData with Diagnosticable {
// Warning: For the sanity of the reader, please make sure these properties
// are in the exact same order as in operator == and in the raw constructor
// and in the order of fields in the class and in the lerp() method.
final List<Object> values = <Object>[
final List<Object?> values = <Object?>[
visualDensity,
primaryColor,
primaryColorBrightness,
......@@ -1779,7 +1777,7 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
///
/// The [materialTheme] parameter must not be null.
MaterialBasedCupertinoThemeData({
@required ThemeData materialTheme,
required ThemeData materialTheme,
}) : this._(
materialTheme,
(materialTheme.cupertinoOverrideTheme ?? const CupertinoThemeData()).noDefault(),
......@@ -1830,12 +1828,12 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
/// instead.
@override
MaterialBasedCupertinoThemeData copyWith({
Brightness brightness,
Color primaryColor,
Color primaryContrastingColor,
CupertinoTextThemeData textTheme,
Color barBackgroundColor,
Color scaffoldBackgroundColor,
Brightness? brightness,
Color? primaryColor,
Color? primaryContrastingColor,
CupertinoTextThemeData? textTheme,
Color? barBackgroundColor,
Color? scaffoldBackgroundColor,
}) {
return MaterialBasedCupertinoThemeData._(
_materialTheme,
......@@ -1909,7 +1907,7 @@ class _FifoCache<K, V> {
V putIfAbsent(K key, V loader()) {
assert(key != null);
assert(loader != null);
final V result = _cache[key];
final V? result = _cache[key];
if (result != null)
return result;
if (_cache.length == _maximumSize)
......@@ -2010,8 +2008,8 @@ class VisualDensity with Diagnosticable {
/// Copy the current [VisualDensity] with the given values replacing the
/// current values.
VisualDensity copyWith({
double horizontal,
double vertical,
double? horizontal,
double? vertical,
}) {
return VisualDensity(
horizontal: horizontal ?? this.horizontal,
......@@ -2070,8 +2068,8 @@ class VisualDensity with Diagnosticable {
/// Linearly interpolate between two densities.
static VisualDensity lerp(VisualDensity a, VisualDensity b, double t) {
return VisualDensity(
horizontal: lerpDouble(a.horizontal, b.horizontal, t),
vertical: lerpDouble(a.horizontal, b.horizontal, t),
horizontal: lerpDouble(a.horizontal, b.horizontal, t)!,
vertical: lerpDouble(a.horizontal, b.horizontal, 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 'dart:ui' show hashValues;
import 'package:flutter/widgets.dart';
......@@ -53,7 +51,7 @@ class TimeOfDay {
///
/// The [hour] argument must be between 0 and 23, inclusive. The [minute]
/// argument must be between 0 and 59, inclusive.
const TimeOfDay({ @required this.hour, @required this.minute });
const TimeOfDay({ required this.hour, required this.minute });
/// Creates a time of day based on the given time.
///
......@@ -79,7 +77,7 @@ class TimeOfDay {
static const int minutesPerHour = 60;
/// Returns a new TimeOfDay with the hour and/or minute replaced.
TimeOfDay replacing({ int hour, int minute }) {
TimeOfDay replacing({ int? hour, int? minute }) {
assert(hour == null || (hour >= 0 && hour < hoursPerDay));
assert(minute == null || (minute >= 0 && minute < minutesPerHour));
return TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute);
......@@ -106,10 +104,10 @@ class TimeOfDay {
String format(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context));
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context)!;
return localizations.formatTimeOfDay(
this,
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat,
alwaysUse24HourFormat: MediaQuery.of(context)!.alwaysUse24HourFormat,
);
}
......@@ -204,7 +202,7 @@ enum HourFormat {
}
/// The [HourFormat] used for the given [TimeOfDayFormat].
HourFormat hourFormat({ @required TimeOfDayFormat of }) {
HourFormat hourFormat({ required TimeOfDayFormat of }) {
switch (of) {
case TimeOfDayFormat.h_colon_mm_space_a:
case TimeOfDayFormat.a_space_h_colon_mm:
......@@ -216,6 +214,4 @@ HourFormat hourFormat({ @required TimeOfDayFormat of }) {
case TimeOfDayFormat.frenchCanadian:
return HourFormat.HH;
}
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:async';
import 'package:flutter/gestures.dart';
......@@ -49,8 +47,8 @@ class Tooltip extends StatefulWidget {
/// All parameters that are defined in the constructor will
/// override the default values _and_ the values in [TooltipTheme.of].
const Tooltip({
Key key,
@required this.message,
Key? key,
required this.message,
this.height,
this.padding,
this.margin,
......@@ -71,12 +69,12 @@ class Tooltip extends StatefulWidget {
/// The height of the tooltip's [child].
///
/// If the [child] is null, then this is the tooltip's intrinsic height.
final double height;
final double? height;
/// The amount of space by which to inset the tooltip's [child].
///
/// Defaults to 16.0 logical pixels in each direction.
final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry? padding;
/// The empty space that surrounds the tooltip.
///
......@@ -89,7 +87,7 @@ class Tooltip extends StatefulWidget {
/// If this property is null, then [TooltipThemeData.margin] is used.
/// If [TooltipThemeData.margin] is also null, the default margin is
/// 0.0 logical pixels on all sides.
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// The vertical gap between the widget and the displayed tooltip.
///
......@@ -98,14 +96,14 @@ class Tooltip extends StatefulWidget {
/// tooltips will position themselves under their corresponding widgets.
/// Otherwise, tooltips will position themselves above their corresponding
/// widgets with the given offset.
final double verticalOffset;
final double? verticalOffset;
/// Whether the tooltip defaults to being displayed below the widget.
///
/// Defaults to true. If there is insufficient space to display the tooltip in
/// the preferred direction, the tooltip will be displayed in the opposite
/// direction.
final bool preferBelow;
final bool? preferBelow;
/// Whether the tooltip's [message] should be excluded from the semantics
/// tree.
......@@ -113,12 +111,12 @@ class Tooltip extends StatefulWidget {
/// Defaults to false. A tooltip will add a [Semantics] label that is set to
/// [Tooltip.message]. Set this property to true if the app is going to
/// provide its own custom semantics label.
final bool excludeFromSemantics;
final bool? excludeFromSemantics;
/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.child}
final Widget child;
final Widget? child;
/// Specifies the tooltip's shape and background color.
///
......@@ -126,7 +124,7 @@ class Tooltip extends StatefulWidget {
/// 4.0. Tooltips will also default to an opacity of 90% and with the color
/// [Colors.grey[700]] if [ThemeData.brightness] is [Brightness.dark], and
/// [Colors.white] if it is [Brightness.light].
final Decoration decoration;
final Decoration? decoration;
/// The style to use for the message of the tooltip.
///
......@@ -136,7 +134,7 @@ class Tooltip extends StatefulWidget {
/// [Colors.white]. Otherwise, if [ThemeData.brightness] is set to
/// [Brightness.light], [TextTheme.bodyText2] of [ThemeData.textTheme] will be
/// used with [Colors.black].
final TextStyle textStyle;
final TextStyle? textStyle;
/// The length of time that a pointer must hover over a tooltip's widget
/// before the tooltip will be shown.
......@@ -145,13 +143,13 @@ class Tooltip extends StatefulWidget {
/// disappear.
///
/// Defaults to 0 milliseconds (tooltips are shown immediately upon hover).
final Duration waitDuration;
final Duration? waitDuration;
/// The length of time that the tooltip will be shown after a long press
/// is released.
///
/// Defaults to 1.5 seconds.
final Duration showDuration;
final Duration? showDuration;
@override
_TooltipState createState() => _TooltipState();
......@@ -183,27 +181,27 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
static const Duration _defaultWaitDuration = Duration(milliseconds: 0);
static const bool _defaultExcludeFromSemantics = false;
double height;
EdgeInsetsGeometry padding;
EdgeInsetsGeometry margin;
Decoration decoration;
TextStyle textStyle;
double verticalOffset;
bool preferBelow;
bool excludeFromSemantics;
AnimationController _controller;
OverlayEntry _entry;
Timer _hideTimer;
Timer _showTimer;
Duration showDuration;
Duration waitDuration;
bool _mouseIsConnected;
late double height;
late EdgeInsetsGeometry padding;
late EdgeInsetsGeometry margin;
late Decoration decoration;
late TextStyle textStyle;
late double verticalOffset;
late bool preferBelow;
late bool excludeFromSemantics;
late AnimationController _controller;
OverlayEntry? _entry;
Timer? _hideTimer;
Timer? _showTimer;
late Duration showDuration;
late Duration waitDuration;
late bool _mouseIsConnected;
bool _longPressActivated = false;
@override
void initState() {
super.initState();
_mouseIsConnected = RendererBinding.instance.mouseTracker.mouseIsConnected;
_mouseIsConnected = RendererBinding.instance!.mouseTracker.mouseIsConnected;
_controller = AnimationController(
duration: _fadeInDuration,
reverseDuration: _fadeOutDuration,
......@@ -211,10 +209,10 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
)
..addStatusListener(_handleStatusChanged);
// Listen to see when a mouse is added.
RendererBinding.instance.mouseTracker.addListener(_handleMouseTrackerChange);
RendererBinding.instance!.mouseTracker.addListener(_handleMouseTrackerChange);
// Listen to global pointer events so that we can hide a tooltip immediately
// if some other control is clicked on.
GestureBinding.instance.pointerRouter.addGlobalRoute(_handlePointerEvent);
GestureBinding.instance!.pointerRouter.addGlobalRoute(_handlePointerEvent);
}
// Forces a rebuild if a mouse has been added or removed.
......@@ -222,7 +220,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
if (!mounted) {
return;
}
final bool mouseIsConnected = RendererBinding.instance.mouseTracker.mouseIsConnected;
final bool mouseIsConnected = RendererBinding.instance!.mouseTracker.mouseIsConnected;
if (mouseIsConnected != _mouseIsConnected) {
setState((){
_mouseIsConnected = mouseIsConnected;
......@@ -287,9 +285,9 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
final OverlayState overlayState = Overlay.of(
context,
debugRequiredFor: widget,
);
)!;
final RenderBox box = context.findRenderObject() as RenderBox;
final RenderBox box = context.findRenderObject()! as RenderBox;
final Offset target = box.localToGlobal(
box.size.center(Offset.zero),
ancestor: overlayState.context.findRenderObject(),
......@@ -299,7 +297,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
// updated values from happening to leak into the overlay when the overlay
// rebuilds.
final Widget overlay = Directionality(
textDirection: Directionality.of(context),
textDirection: Directionality.of(context)!,
child: _TooltipOverlay(
message: widget.message,
height: height,
......@@ -317,7 +315,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
),
);
_entry = OverlayEntry(builder: (BuildContext context) => overlay);
overlayState.insert(_entry);
overlayState.insert(_entry!);
SemanticsService.tooltip(widget.message);
}
......@@ -352,8 +350,8 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
@override
void dispose() {
GestureBinding.instance.pointerRouter.removeGlobalRoute(_handlePointerEvent);
RendererBinding.instance.mouseTracker.removeListener(_handleMouseTrackerChange);
GestureBinding.instance!.pointerRouter.removeGlobalRoute(_handlePointerEvent);
RendererBinding.instance!.mouseTracker.removeListener(_handleMouseTrackerChange);
if (_entry != null)
_removeEntry();
_controller.dispose();
......@@ -370,12 +368,12 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
assert(Overlay.of(context, debugRequiredFor: widget) != null);
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
final TooltipThemeData tooltipTheme = TooltipTheme.of(context);
TextStyle defaultTextStyle;
BoxDecoration defaultDecoration;
if (theme.brightness == Brightness.dark) {
defaultTextStyle = theme.textTheme.bodyText2.copyWith(
defaultTextStyle = theme.textTheme.bodyText2!.copyWith(
color: Colors.black,
);
defaultDecoration = BoxDecoration(
......@@ -383,11 +381,11 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
borderRadius: const BorderRadius.all(Radius.circular(4)),
);
} else {
defaultTextStyle = theme.textTheme.bodyText2.copyWith(
defaultTextStyle = theme.textTheme.bodyText2!.copyWith(
color: Colors.white,
);
defaultDecoration = BoxDecoration(
color: Colors.grey[700].withOpacity(0.9),
color: Colors.grey[700]!.withOpacity(0.9),
borderRadius: const BorderRadius.all(Radius.circular(4)),
);
}
......@@ -433,9 +431,9 @@ class _TooltipPositionDelegate extends SingleChildLayoutDelegate {
///
/// The arguments must not be null.
_TooltipPositionDelegate({
@required this.target,
@required this.verticalOffset,
@required this.preferBelow,
required this.target,
required this.verticalOffset,
required this.preferBelow,
}) : assert(target != null),
assert(verticalOffset != null),
assert(preferBelow != null);
......@@ -478,25 +476,25 @@ class _TooltipPositionDelegate extends SingleChildLayoutDelegate {
class _TooltipOverlay extends StatelessWidget {
const _TooltipOverlay({
Key key,
this.message,
this.height,
Key? key,
required this.message,
required this.height,
this.padding,
this.margin,
this.decoration,
this.textStyle,
this.animation,
this.target,
this.verticalOffset,
this.preferBelow,
required this.animation,
required this.target,
required this.verticalOffset,
required this.preferBelow,
}) : super(key: key);
final String message;
final double height;
final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry margin;
final Decoration decoration;
final TextStyle textStyle;
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry? margin;
final Decoration? decoration;
final TextStyle? textStyle;
final Animation<double> animation;
final Offset target;
final double verticalOffset;
......@@ -517,7 +515,7 @@ class _TooltipOverlay extends StatelessWidget {
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: height),
child: DefaultTextStyle(
style: Theme.of(context).textTheme.bodyText2,
style: Theme.of(context)!.textTheme.bodyText2,
child: Container(
decoration: decoration,
padding: padding,
......
......@@ -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';
......@@ -42,13 +40,13 @@ class TooltipThemeData with Diagnosticable {
});
/// The height of [Tooltip.child].
final double height;
final double? height;
/// If provided, the amount of space by which to inset [Tooltip.child].
final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry? padding;
/// If provided, the amount of empty space to surround the [Tooltip].
final EdgeInsetsGeometry margin;
final EdgeInsetsGeometry? margin;
/// The vertical gap between the widget and the displayed tooltip.
///
......@@ -57,13 +55,13 @@ class TooltipThemeData with Diagnosticable {
/// tooltips will position themselves under their corresponding widgets.
/// Otherwise, tooltips will position themselves above their corresponding
/// widgets with the given offset.
final double verticalOffset;
final double? verticalOffset;
/// Whether the tooltip is displayed below its widget by default.
///
/// If there is insufficient space to display the tooltip in the preferred
/// direction, the tooltip will be displayed in the opposite direction.
final bool preferBelow;
final bool? preferBelow;
/// Whether the [Tooltip.message] should be excluded from the semantics
/// tree.
......@@ -71,34 +69,34 @@ class TooltipThemeData with Diagnosticable {
/// By default, [Tooltip]s will add a [Semantics] label that is set to
/// [Tooltip.message]. Set this property to true if the app is going to
/// provide its own custom semantics label.
final bool excludeFromSemantics;
final bool? excludeFromSemantics;
/// The [Tooltip]'s shape and background color.
final Decoration decoration;
final Decoration? decoration;
/// The style to use for the message of [Tooltip]s.
final TextStyle textStyle;
final TextStyle? textStyle;
/// The length of time that a pointer must hover over a tooltip's widget
/// before the tooltip will be shown.
final Duration waitDuration;
final Duration? waitDuration;
/// The length of time that the tooltip will be shown once it has appeared.
final Duration showDuration;
final Duration? showDuration;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
TooltipThemeData copyWith({
double height,
EdgeInsetsGeometry padding,
EdgeInsetsGeometry margin,
double verticalOffset,
bool preferBelow,
bool excludeFromSemantics,
Decoration decoration,
TextStyle textStyle,
Duration waitDuration,
Duration showDuration,
double? height,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? margin,
double? verticalOffset,
bool? preferBelow,
bool? excludeFromSemantics,
Decoration? decoration,
TextStyle? textStyle,
Duration? waitDuration,
Duration? showDuration,
}) {
return TooltipThemeData(
height: height ?? this.height,
......@@ -119,7 +117,7 @@ class TooltipThemeData with Diagnosticable {
/// If both arguments are null, then null is returned.
///
/// {@macro dart.ui.shadow.lerp}
static TooltipThemeData lerp(TooltipThemeData a, TooltipThemeData b, double t) {
static TooltipThemeData? lerp(TooltipThemeData? a, TooltipThemeData? b, double t) {
if (a == null && b == null)
return null;
assert(t != null);
......@@ -128,8 +126,8 @@ class TooltipThemeData with Diagnosticable {
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t),
verticalOffset: lerpDouble(a?.verticalOffset, b?.verticalOffset, t),
preferBelow: t < 0.5 ? a.preferBelow: b.preferBelow,
excludeFromSemantics: t < 0.5 ? a.excludeFromSemantics : b.excludeFromSemantics,
preferBelow: t < 0.5 ? a?.preferBelow: b?.preferBelow,
excludeFromSemantics: t < 0.5 ? a?.excludeFromSemantics : b?.excludeFromSemantics,
decoration: Decoration.lerp(a?.decoration, b?.decoration, t),
textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t),
);
......@@ -222,9 +220,9 @@ class TooltipTheme extends InheritedTheme {
///
/// The data argument must not be null.
const TooltipTheme({
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 for descendant [Tooltip] widgets.
......@@ -240,13 +238,13 @@ class TooltipTheme extends InheritedTheme {
/// TooltipThemeData theme = TooltipTheme.of(context);
/// ```
static TooltipThemeData of(BuildContext context) {
final TooltipTheme tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>();
return tooltipTheme?.data ?? Theme.of(context).tooltipTheme;
final TooltipTheme? tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>();
return tooltipTheme?.data ?? Theme.of(context)!.tooltipTheme;
}
@override
Widget wrap(BuildContext context, Widget child) {
final TooltipTheme ancestorTheme = context.findAncestorWidgetOfExactType<TooltipTheme>();
final TooltipTheme? ancestorTheme = context.findAncestorWidgetOfExactType<TooltipTheme>();
return identical(this, ancestorTheme) ? child : TooltipTheme(data: data, child: child);
}
......
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