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 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble; import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -46,44 +44,44 @@ class CardTheme with Diagnosticable { ...@@ -46,44 +44,44 @@ class CardTheme with Diagnosticable {
/// Default value for [Card.clipBehavior]. /// Default value for [Card.clipBehavior].
/// ///
/// If null, [Card] uses [Clip.none]. /// If null, [Card] uses [Clip.none].
final Clip clipBehavior; final Clip? clipBehavior;
/// Default value for [Card.color]. /// Default value for [Card.color].
/// ///
/// If null, [Card] uses [ThemeData.cardColor]. /// If null, [Card] uses [ThemeData.cardColor].
final Color color; final Color? color;
/// Default value for [Card.shadowColor]. /// Default value for [Card.shadowColor].
/// ///
/// If null, [Card] defaults to fully opaque black. /// If null, [Card] defaults to fully opaque black.
final Color shadowColor; final Color? shadowColor;
/// Default value for [Card.elevation]. /// Default value for [Card.elevation].
/// ///
/// If null, [Card] uses a default of 1.0. /// If null, [Card] uses a default of 1.0.
final double elevation; final double? elevation;
/// Default value for [Card.margin]. /// Default value for [Card.margin].
/// ///
/// If null, [Card] uses a default margin of 4.0 logical pixels on all sides: /// If null, [Card] uses a default margin of 4.0 logical pixels on all sides:
/// `EdgeInsets.all(4.0)`. /// `EdgeInsets.all(4.0)`.
final EdgeInsetsGeometry margin; final EdgeInsetsGeometry? margin;
/// Default value for [Card.shape]. /// Default value for [Card.shape].
/// ///
/// If null, [Card] then uses a [RoundedRectangleBorder] with a circular /// If null, [Card] then uses a [RoundedRectangleBorder] with a circular
/// corner radius of 4.0. /// corner radius of 4.0.
final ShapeBorder shape; final ShapeBorder? shape;
/// Creates a copy of this object with the given fields replaced with the /// Creates a copy of this object with the given fields replaced with the
/// new values. /// new values.
CardTheme copyWith({ CardTheme copyWith({
Clip clipBehavior, Clip? clipBehavior,
Color color, Color? color,
Color shadowColor, Color? shadowColor,
double elevation, double? elevation,
EdgeInsetsGeometry margin, EdgeInsetsGeometry? margin,
ShapeBorder shape, ShapeBorder? shape,
}) { }) {
return CardTheme( return CardTheme(
clipBehavior: clipBehavior ?? this.clipBehavior, clipBehavior: clipBehavior ?? this.clipBehavior,
...@@ -97,7 +95,7 @@ class CardTheme with Diagnosticable { ...@@ -97,7 +95,7 @@ class CardTheme with Diagnosticable {
/// The [ThemeData.cardTheme] property of the ambient [Theme]. /// The [ThemeData.cardTheme] property of the ambient [Theme].
static CardTheme of(BuildContext context) { static CardTheme of(BuildContext context) {
return Theme.of(context).cardTheme; return Theme.of(context)!.cardTheme;
} }
/// Linearly interpolate between two Card themes. /// Linearly interpolate between two Card themes.
...@@ -105,7 +103,7 @@ class CardTheme with Diagnosticable { ...@@ -105,7 +103,7 @@ class CardTheme with Diagnosticable {
/// The argument `t` must not be null. /// The argument `t` must not be null.
/// ///
/// {@macro dart.ui.shadow.lerp} /// {@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); assert(t != null);
return CardTheme( return CardTheme(
clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior, clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -45,7 +43,7 @@ class ElevationOverlay { ...@@ -45,7 +43,7 @@ class ElevationOverlay {
/// * <https://material.io/design/color/dark-theme.html>, which specifies how /// * <https://material.io/design/color/dark-theme.html>, which specifies how
/// the overlay should be applied. /// the overlay should be applied.
static Color applyOverlay(BuildContext context, Color color, double elevation) { 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 && if (elevation > 0.0 &&
theme.applyElevationOverlayColor && theme.applyElevationOverlayColor &&
theme.brightness == Brightness.dark && theme.brightness == Brightness.dark &&
...@@ -63,7 +61,7 @@ class ElevationOverlay { ...@@ -63,7 +61,7 @@ class ElevationOverlay {
/// * https://material.io/design/color/dark-theme.html#properties which /// * https://material.io/design/color/dark-theme.html#properties which
/// specifies the exact overlay values for a given elevation. /// specifies the exact overlay values for a given elevation.
static Color overlayColor(BuildContext context, double 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 // Compute the opacity for the given elevation
// This formula matches the values in the spec: // This formula matches the values in the spec:
// https://material.io/design/color/dark-theme.html#properties // https://material.io/design/color/dark-theme.html#properties
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -94,7 +92,7 @@ class Feedback { ...@@ -94,7 +92,7 @@ class Feedback {
/// * [wrapForTap] to trigger platform-specific feedback before executing a /// * [wrapForTap] to trigger platform-specific feedback before executing a
/// [GestureTapCallback]. /// [GestureTapCallback].
static Future<void> forTap(BuildContext context) async { static Future<void> forTap(BuildContext context) async {
context.findRenderObject().sendSemanticsEvent(const TapSemanticEvent()); context.findRenderObject()!.sendSemanticsEvent(const TapSemanticEvent());
switch (_platform(context)) { switch (_platform(context)) {
case TargetPlatform.android: case TargetPlatform.android:
case TargetPlatform.fuchsia: case TargetPlatform.fuchsia:
...@@ -104,10 +102,7 @@ class Feedback { ...@@ -104,10 +102,7 @@ class Feedback {
case TargetPlatform.macOS: case TargetPlatform.macOS:
case TargetPlatform.windows: case TargetPlatform.windows:
return Future<void>.value(); 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 /// Wraps a [GestureTapCallback] to provide platform specific feedback for a
...@@ -120,7 +115,7 @@ class Feedback { ...@@ -120,7 +115,7 @@ class Feedback {
/// ///
/// * [forTap] to just trigger the platform-specific feedback without wrapping /// * [forTap] to just trigger the platform-specific feedback without wrapping
/// a [GestureTapCallback]. /// a [GestureTapCallback].
static GestureTapCallback wrapForTap(GestureTapCallback callback, BuildContext context) { static GestureTapCallback? wrapForTap(GestureTapCallback? callback, BuildContext context) {
if (callback == null) if (callback == null)
return null; return null;
return () { return () {
...@@ -139,7 +134,7 @@ class Feedback { ...@@ -139,7 +134,7 @@ class Feedback {
/// * [wrapForLongPress] to trigger platform-specific feedback before /// * [wrapForLongPress] to trigger platform-specific feedback before
/// executing a [GestureLongPressCallback]. /// executing a [GestureLongPressCallback].
static Future<void> forLongPress(BuildContext context) { static Future<void> forLongPress(BuildContext context) {
context.findRenderObject().sendSemanticsEvent(const LongPressSemanticsEvent()); context.findRenderObject()!.sendSemanticsEvent(const LongPressSemanticsEvent());
switch (_platform(context)) { switch (_platform(context)) {
case TargetPlatform.android: case TargetPlatform.android:
case TargetPlatform.fuchsia: case TargetPlatform.fuchsia:
...@@ -149,10 +144,7 @@ class Feedback { ...@@ -149,10 +144,7 @@ class Feedback {
case TargetPlatform.macOS: case TargetPlatform.macOS:
case TargetPlatform.windows: case TargetPlatform.windows:
return Future<void>.value(); return Future<void>.value();
break;
} }
assert(false, 'Unhandled TargetPlatform ${_platform(context)}');
return Future<void>.value();
} }
/// Wraps a [GestureLongPressCallback] to provide platform specific feedback /// Wraps a [GestureLongPressCallback] to provide platform specific feedback
...@@ -166,7 +158,7 @@ class Feedback { ...@@ -166,7 +158,7 @@ class Feedback {
/// ///
/// * [forLongPress] to just trigger the platform-specific feedback without /// * [forLongPress] to just trigger the platform-specific feedback without
/// wrapping a [GestureLongPressCallback]. /// wrapping a [GestureLongPressCallback].
static GestureLongPressCallback wrapForLongPress(GestureLongPressCallback callback, BuildContext context) { static GestureLongPressCallback? wrapForLongPress(GestureLongPressCallback? callback, BuildContext context) {
if (callback == null) if (callback == null)
return null; return null;
return () { return () {
...@@ -175,5 +167,5 @@ class Feedback { ...@@ -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 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -135,7 +133,7 @@ abstract class MaterialLocalizations { ...@@ -135,7 +133,7 @@ abstract class MaterialLocalizations {
/// there are, e.g. 'Tab 1 of 2' in United States English. /// there are, e.g. 'Tab 1 of 2' in United States English.
/// ///
/// `tabIndex` and `tabCount` must be greater than or equal to one. /// `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. /// Title for the [PaginatedDataTable]'s selected row count header.
String selectedRowCountTitle(int selectedRowCount); String selectedRowCountTitle(int selectedRowCount);
...@@ -319,7 +317,7 @@ abstract class MaterialLocalizations { ...@@ -319,7 +317,7 @@ abstract class MaterialLocalizations {
/// ///
/// See also: /// See also:
/// * [formatCompactDate], which will convert a [DateTime] into a string in the compact format. /// * [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 /// List of week day names in narrow format, usually 1- or 2-letter
/// abbreviations of full names. /// abbreviations of full names.
...@@ -505,7 +503,7 @@ abstract class MaterialLocalizations { ...@@ -505,7 +503,7 @@ abstract class MaterialLocalizations {
/// ```dart /// ```dart
/// tooltip: MaterialLocalizations.of(context).backButtonTooltip, /// tooltip: MaterialLocalizations.of(context).backButtonTooltip,
/// ``` /// ```
static MaterialLocalizations of(BuildContext context) { static MaterialLocalizations? of(BuildContext context) {
return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations); return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
} }
} }
...@@ -696,24 +694,28 @@ class DefaultMaterialLocalizations implements MaterialLocalizations { ...@@ -696,24 +694,28 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
} }
@override @override
DateTime parseCompactDate(String inputString) { DateTime? parseCompactDate(String? inputString) {
if (inputString == null) {
return null;
}
// Assumes US mm/dd/yyyy format // Assumes US mm/dd/yyyy format
final List<String> inputParts = inputString.split('/'); final List<String> inputParts = inputString.split('/');
if (inputParts.length != 3) { if (inputParts.length != 3) {
return null; 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) { if (year == null || year < 1) {
return null; 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) { if (month == null || month < 1 || month > 12) {
return null; 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)) { if (day == null || day < 1 || day > _getDaysInMonth(year, month)) {
return null; return null;
} }
...@@ -808,7 +810,6 @@ class DefaultMaterialLocalizations implements MaterialLocalizations { ...@@ -808,7 +810,6 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
case DayPeriod.pm: case DayPeriod.pm:
return postMeridiemAbbreviation; return postMeridiemAbbreviation;
} }
return null;
} }
@override @override
...@@ -932,7 +933,7 @@ class DefaultMaterialLocalizations implements MaterialLocalizations { ...@@ -932,7 +933,7 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
String get rowsPerPageTitle => 'Rows per page:'; String get rowsPerPageTitle => 'Rows per page:';
@override @override
String tabLabel({ int tabIndex, int tabCount }) { String tabLabel({ required int tabIndex, required int tabCount }) {
assert(tabIndex >= 1); assert(tabIndex >= 1);
assert(tabCount >= 1); assert(tabCount >= 1);
return 'Tab $tabIndex of $tabCount'; return 'Tab $tabIndex of $tabCount';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble; import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -67,30 +65,30 @@ class SnackBarThemeData with Diagnosticable { ...@@ -67,30 +65,30 @@ class SnackBarThemeData with Diagnosticable {
/// Default value for [SnackBar.backgroundColor]. /// Default value for [SnackBar.backgroundColor].
/// ///
/// If null, [SnackBar] defaults to dark grey: `Color(0xFF323232)`. /// If null, [SnackBar] defaults to dark grey: `Color(0xFF323232)`.
final Color backgroundColor; final Color? backgroundColor;
/// Default value for [SnackBarAction.textColor]. /// Default value for [SnackBarAction.textColor].
/// ///
/// If null, [SnackBarAction] defaults to [ColorScheme.secondary] of /// If null, [SnackBarAction] defaults to [ColorScheme.secondary] of
/// [ThemeData.colorScheme] . /// [ThemeData.colorScheme] .
final Color actionTextColor; final Color? actionTextColor;
/// Default value for [SnackBarAction.disabledTextColor]. /// Default value for [SnackBarAction.disabledTextColor].
/// ///
/// If null, [SnackBarAction] defaults to [ColorScheme.onSurface] with its /// If null, [SnackBarAction] defaults to [ColorScheme.onSurface] with its
/// opacity set to 0.30 if the [Theme]'s brightness is [Brightness.dark], 0.38 /// opacity set to 0.30 if the [Theme]'s brightness is [Brightness.dark], 0.38
/// otherwise. /// otherwise.
final Color disabledActionTextColor; final Color? disabledActionTextColor;
/// Used to configure the [DefaultTextStyle] for the [SnackBar.content] widget. /// Used to configure the [DefaultTextStyle] for the [SnackBar.content] widget.
/// ///
/// If null, [SnackBar] defines its default. /// If null, [SnackBar] defines its default.
final TextStyle contentTextStyle; final TextStyle? contentTextStyle;
/// Default value for [SnackBar.elevation]. /// Default value for [SnackBar.elevation].
/// ///
/// If null, [SnackBar] uses a default of 6.0. /// If null, [SnackBar] uses a default of 6.0.
final double elevation; final double? elevation;
/// Default value for [SnackBar.shape]. /// Default value for [SnackBar.shape].
/// ///
...@@ -99,23 +97,23 @@ class SnackBarThemeData with Diagnosticable { ...@@ -99,23 +97,23 @@ class SnackBarThemeData with Diagnosticable {
/// specified, so the [SnackBar] is rectangular. For /// specified, so the [SnackBar] is rectangular. For
/// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a /// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a
/// circular corner radius of 4.0. /// circular corner radius of 4.0.
final ShapeBorder shape; final ShapeBorder? shape;
/// Default value for [SnackBar.behavior]. /// Default value for [SnackBar.behavior].
/// ///
/// If null, [SnackBar] will default to [SnackBarBehavior.fixed]. /// 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 /// Creates a copy of this object with the given fields replaced with the
/// new values. /// new values.
SnackBarThemeData copyWith({ SnackBarThemeData copyWith({
Color backgroundColor, Color? backgroundColor,
Color actionTextColor, Color? actionTextColor,
Color disabledActionTextColor, Color? disabledActionTextColor,
TextStyle contentTextStyle, TextStyle? contentTextStyle,
double elevation, double? elevation,
ShapeBorder shape, ShapeBorder? shape,
SnackBarBehavior behavior, SnackBarBehavior? behavior,
}) { }) {
return SnackBarThemeData( return SnackBarThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor, backgroundColor: backgroundColor ?? this.backgroundColor,
...@@ -133,7 +131,7 @@ class SnackBarThemeData with Diagnosticable { ...@@ -133,7 +131,7 @@ class SnackBarThemeData with Diagnosticable {
/// The argument `t` must not be null. /// The argument `t` must not be null.
/// ///
/// {@macro dart.ui.shadow.lerp} /// {@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); assert(t != null);
return SnackBarThemeData( return SnackBarThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
...@@ -142,7 +140,7 @@ class SnackBarThemeData with Diagnosticable { ...@@ -142,7 +140,7 @@ class SnackBarThemeData with Diagnosticable {
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t), elevation: lerpDouble(a?.elevation, b?.elevation, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, 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 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -40,10 +38,10 @@ class Theme extends StatelessWidget { ...@@ -40,10 +38,10 @@ class Theme extends StatelessWidget {
/// ///
/// The [data] and [child] arguments must not be null. /// The [data] and [child] arguments must not be null.
const Theme({ const Theme({
Key key, Key? key,
@required this.data, required this.data,
this.isMaterialAppTheme = false, this.isMaterialAppTheme = false,
@required this.child, required this.child,
}) : assert(child != null), }) : assert(child != null),
assert(data != null), assert(data != null),
super(key: key); super(key: key);
...@@ -126,17 +124,17 @@ class Theme extends StatelessWidget { ...@@ -126,17 +124,17 @@ class Theme extends StatelessWidget {
/// ); /// );
/// } /// }
/// ``` /// ```
static ThemeData of(BuildContext context, { bool shadowThemeOnly = false }) { static ThemeData? of(BuildContext context, { bool shadowThemeOnly = false }) {
final _InheritedTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>(); final _InheritedTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
if (shadowThemeOnly) { if (shadowThemeOnly) {
if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme) if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme)
return null; return null;
return inheritedTheme.theme.data; return inheritedTheme.theme.data;
} }
final MaterialLocalizations localizations = MaterialLocalizations.of(context); final MaterialLocalizations? localizations = MaterialLocalizations.of(context);
final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike; 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)); return ThemeData.localize(theme, theme.typography.geometryThemeFor(category));
} }
...@@ -168,9 +166,9 @@ class Theme extends StatelessWidget { ...@@ -168,9 +166,9 @@ class Theme extends StatelessWidget {
class _InheritedTheme extends InheritedTheme { class _InheritedTheme extends InheritedTheme {
const _InheritedTheme({ const _InheritedTheme({
Key key, Key? key,
@required this.theme, required this.theme,
@required Widget child, required Widget child,
}) : assert(theme != null), }) : assert(theme != null),
super(key: key, child: child); super(key: key, child: child);
...@@ -178,7 +176,7 @@ class _InheritedTheme extends InheritedTheme { ...@@ -178,7 +176,7 @@ class _InheritedTheme extends InheritedTheme {
@override @override
Widget wrap(BuildContext context, Widget child) { 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); return identical(this, ancestorTheme) ? child : Theme(data: theme.data, child: child);
} }
...@@ -198,10 +196,10 @@ class ThemeDataTween extends Tween<ThemeData> { ...@@ -198,10 +196,10 @@ class ThemeDataTween extends Tween<ThemeData> {
/// The [begin] and [end] properties must be non-null before the tween is /// 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 /// first used, but the arguments can be null if the values are going to be
/// filled in later. /// filled in later.
ThemeDataTween({ ThemeData begin, ThemeData end }) : super(begin: begin, end: end); ThemeDataTween({ ThemeData? begin, ThemeData? end }) : super(begin: begin, end: end);
@override @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, /// Animated version of [Theme] which automatically transitions the colors,
...@@ -224,13 +222,13 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget { ...@@ -224,13 +222,13 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget {
/// By default, the theme transition uses a linear curve. The [data] and /// By default, the theme transition uses a linear curve. The [data] and
/// [child] arguments must not be null. /// [child] arguments must not be null.
const AnimatedTheme({ const AnimatedTheme({
Key key, Key? key,
@required this.data, required this.data,
this.isMaterialAppTheme = false, this.isMaterialAppTheme = false,
Curve curve = Curves.linear, Curve curve = Curves.linear,
Duration duration = kThemeAnimationDuration, Duration duration = kThemeAnimationDuration,
VoidCallback onEnd, VoidCallback? onEnd,
@required this.child, required this.child,
}) : assert(child != null), }) : assert(child != null),
assert(data != null), assert(data != null),
super(key: key, curve: curve, duration: duration, onEnd: onEnd); super(key: key, curve: curve, duration: duration, onEnd: onEnd);
...@@ -251,7 +249,7 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget { ...@@ -251,7 +249,7 @@ class AnimatedTheme extends ImplicitlyAnimatedWidget {
} }
class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> { class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> {
ThemeDataTween _data; ThemeDataTween? _data;
@override @override
void forEachTween(TweenVisitor<dynamic> visitor) { void forEachTween(TweenVisitor<dynamic> visitor) {
...@@ -265,7 +263,7 @@ class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> { ...@@ -265,7 +263,7 @@ class _AnimatedThemeState extends AnimatedWidgetBaseState<AnimatedTheme> {
return Theme( return Theme(
isMaterialAppTheme: widget.isMaterialAppTheme, isMaterialAppTheme: widget.isMaterialAppTheme,
child: widget.child, child: widget.child,
data: _data.evaluate(animation), data: _data!.evaluate(animation!),
); );
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show hashValues; import 'dart:ui' show hashValues;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -53,7 +51,7 @@ class TimeOfDay { ...@@ -53,7 +51,7 @@ class TimeOfDay {
/// ///
/// The [hour] argument must be between 0 and 23, inclusive. The [minute] /// The [hour] argument must be between 0 and 23, inclusive. The [minute]
/// argument must be between 0 and 59, inclusive. /// 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. /// Creates a time of day based on the given time.
/// ///
...@@ -79,7 +77,7 @@ class TimeOfDay { ...@@ -79,7 +77,7 @@ class TimeOfDay {
static const int minutesPerHour = 60; static const int minutesPerHour = 60;
/// Returns a new TimeOfDay with the hour and/or minute replaced. /// 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(hour == null || (hour >= 0 && hour < hoursPerDay));
assert(minute == null || (minute >= 0 && minute < minutesPerHour)); assert(minute == null || (minute >= 0 && minute < minutesPerHour));
return TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute); return TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute);
...@@ -106,10 +104,10 @@ class TimeOfDay { ...@@ -106,10 +104,10 @@ class TimeOfDay {
String format(BuildContext context) { String format(BuildContext context) {
assert(debugCheckHasMediaQuery(context)); assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final MaterialLocalizations localizations = MaterialLocalizations.of(context); final MaterialLocalizations localizations = MaterialLocalizations.of(context)!;
return localizations.formatTimeOfDay( return localizations.formatTimeOfDay(
this, this,
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat, alwaysUse24HourFormat: MediaQuery.of(context)!.alwaysUse24HourFormat,
); );
} }
...@@ -204,7 +202,7 @@ enum HourFormat { ...@@ -204,7 +202,7 @@ enum HourFormat {
} }
/// The [HourFormat] used for the given [TimeOfDayFormat]. /// The [HourFormat] used for the given [TimeOfDayFormat].
HourFormat hourFormat({ @required TimeOfDayFormat of }) { HourFormat hourFormat({ required TimeOfDayFormat of }) {
switch (of) { switch (of) {
case TimeOfDayFormat.h_colon_mm_space_a: case TimeOfDayFormat.h_colon_mm_space_a:
case TimeOfDayFormat.a_space_h_colon_mm: case TimeOfDayFormat.a_space_h_colon_mm:
...@@ -216,6 +214,4 @@ HourFormat hourFormat({ @required TimeOfDayFormat of }) { ...@@ -216,6 +214,4 @@ HourFormat hourFormat({ @required TimeOfDayFormat of }) {
case TimeOfDayFormat.frenchCanadian: case TimeOfDayFormat.frenchCanadian:
return HourFormat.HH; return HourFormat.HH;
} }
return null;
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble; import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -42,13 +40,13 @@ class TooltipThemeData with Diagnosticable { ...@@ -42,13 +40,13 @@ class TooltipThemeData with Diagnosticable {
}); });
/// The height of [Tooltip.child]. /// The height of [Tooltip.child].
final double height; final double? height;
/// If provided, the amount of space by which to inset [Tooltip.child]. /// 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]. /// 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. /// The vertical gap between the widget and the displayed tooltip.
/// ///
...@@ -57,13 +55,13 @@ class TooltipThemeData with Diagnosticable { ...@@ -57,13 +55,13 @@ class TooltipThemeData with Diagnosticable {
/// tooltips will position themselves under their corresponding widgets. /// tooltips will position themselves under their corresponding widgets.
/// Otherwise, tooltips will position themselves above their corresponding /// Otherwise, tooltips will position themselves above their corresponding
/// widgets with the given offset. /// widgets with the given offset.
final double verticalOffset; final double? verticalOffset;
/// Whether the tooltip is displayed below its widget by default. /// Whether the tooltip is displayed below its widget by default.
/// ///
/// If there is insufficient space to display the tooltip in the preferred /// If there is insufficient space to display the tooltip in the preferred
/// direction, the tooltip will be displayed in the opposite direction. /// 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 /// Whether the [Tooltip.message] should be excluded from the semantics
/// tree. /// tree.
...@@ -71,34 +69,34 @@ class TooltipThemeData with Diagnosticable { ...@@ -71,34 +69,34 @@ class TooltipThemeData with Diagnosticable {
/// By default, [Tooltip]s will add a [Semantics] label that is set to /// 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 /// [Tooltip.message]. Set this property to true if the app is going to
/// provide its own custom semantics label. /// provide its own custom semantics label.
final bool excludeFromSemantics; final bool? excludeFromSemantics;
/// The [Tooltip]'s shape and background color. /// The [Tooltip]'s shape and background color.
final Decoration decoration; final Decoration? decoration;
/// The style to use for the message of [Tooltip]s. /// 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 /// The length of time that a pointer must hover over a tooltip's widget
/// before the tooltip will be shown. /// 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. /// 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 /// Creates a copy of this object but with the given fields replaced with the
/// new values. /// new values.
TooltipThemeData copyWith({ TooltipThemeData copyWith({
double height, double? height,
EdgeInsetsGeometry padding, EdgeInsetsGeometry? padding,
EdgeInsetsGeometry margin, EdgeInsetsGeometry? margin,
double verticalOffset, double? verticalOffset,
bool preferBelow, bool? preferBelow,
bool excludeFromSemantics, bool? excludeFromSemantics,
Decoration decoration, Decoration? decoration,
TextStyle textStyle, TextStyle? textStyle,
Duration waitDuration, Duration? waitDuration,
Duration showDuration, Duration? showDuration,
}) { }) {
return TooltipThemeData( return TooltipThemeData(
height: height ?? this.height, height: height ?? this.height,
...@@ -119,7 +117,7 @@ class TooltipThemeData with Diagnosticable { ...@@ -119,7 +117,7 @@ class TooltipThemeData with Diagnosticable {
/// If both arguments are null, then null is returned. /// If both arguments are null, then null is returned.
/// ///
/// {@macro dart.ui.shadow.lerp} /// {@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) if (a == null && b == null)
return null; return null;
assert(t != null); assert(t != null);
...@@ -128,8 +126,8 @@ class TooltipThemeData with Diagnosticable { ...@@ -128,8 +126,8 @@ class TooltipThemeData with Diagnosticable {
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t), margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t),
verticalOffset: lerpDouble(a?.verticalOffset, b?.verticalOffset, t), verticalOffset: lerpDouble(a?.verticalOffset, b?.verticalOffset, t),
preferBelow: t < 0.5 ? a.preferBelow: b.preferBelow, preferBelow: t < 0.5 ? a?.preferBelow: b?.preferBelow,
excludeFromSemantics: t < 0.5 ? a.excludeFromSemantics : b.excludeFromSemantics, excludeFromSemantics: t < 0.5 ? a?.excludeFromSemantics : b?.excludeFromSemantics,
decoration: Decoration.lerp(a?.decoration, b?.decoration, t), decoration: Decoration.lerp(a?.decoration, b?.decoration, t),
textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t), textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t),
); );
...@@ -222,9 +220,9 @@ class TooltipTheme extends InheritedTheme { ...@@ -222,9 +220,9 @@ class TooltipTheme extends InheritedTheme {
/// ///
/// The data argument must not be null. /// The data argument must not be null.
const TooltipTheme({ const TooltipTheme({
Key key, Key? key,
@required this.data, required this.data,
Widget child, required Widget child,
}) : assert(data != null), super(key: key, child: child); }) : assert(data != null), super(key: key, child: child);
/// The properties for descendant [Tooltip] widgets. /// The properties for descendant [Tooltip] widgets.
...@@ -240,13 +238,13 @@ class TooltipTheme extends InheritedTheme { ...@@ -240,13 +238,13 @@ class TooltipTheme extends InheritedTheme {
/// TooltipThemeData theme = TooltipTheme.of(context); /// TooltipThemeData theme = TooltipTheme.of(context);
/// ``` /// ```
static TooltipThemeData of(BuildContext context) { static TooltipThemeData of(BuildContext context) {
final TooltipTheme tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>(); final TooltipTheme? tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>();
return tooltipTheme?.data ?? Theme.of(context).tooltipTheme; return tooltipTheme?.data ?? Theme.of(context)!.tooltipTheme;
} }
@override @override
Widget wrap(BuildContext context, Widget child) { 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); 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