Unverified Commit a0a65fc6 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Revert "migrate some material files to nullsafety (#67078)" (#67183)

This reverts commit 81439922.
parent cbf1e135
This diff is collapsed.
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -44,54 +46,54 @@ class AppBarTheme with Diagnosticable {
/// Default value for [AppBar.brightness].
///
/// If null, [AppBar] uses [ThemeData.primaryColorBrightness].
final Brightness? brightness;
final Brightness brightness;
/// Default value for [AppBar.backgroundColor].
///
/// If null, [AppBar] uses [ThemeData.primaryColor].
final Color? color;
final Color color;
/// Default value for [AppBar.elevation].
///
/// If null, [AppBar] uses a default value of 4.0.
final double? elevation;
final double elevation;
/// Default value for [AppBar.shadowColor].
///
/// If null, [AppBar] uses a default value of fully opaque black.
final Color? shadowColor;
final Color shadowColor;
/// Default value for [AppBar.iconTheme].
///
/// If null, [AppBar] uses [ThemeData.primaryIconTheme].
final IconThemeData? iconTheme;
final IconThemeData iconTheme;
/// Default value for [AppBar.actionsIconTheme].
///
/// If null, [AppBar] uses [ThemeData.primaryIconTheme].
final IconThemeData? actionsIconTheme;
final IconThemeData actionsIconTheme;
/// Default value for [AppBar.textTheme].
///
/// If null, [AppBar] uses [ThemeData.primaryTextTheme].
final TextTheme? textTheme;
final TextTheme textTheme;
/// Default value for [AppBar.centerTitle].
///
/// If null, the value is adapted to current [TargetPlatform].
final bool? centerTitle;
final bool centerTitle;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
AppBarTheme copyWith({
IconThemeData? actionsIconTheme,
Brightness? brightness,
Color? color,
double? elevation,
Color? shadowColor,
IconThemeData? iconTheme,
TextTheme? textTheme,
bool? centerTitle,
IconThemeData actionsIconTheme,
Brightness brightness,
Color color,
double elevation,
Color shadowColor,
IconThemeData iconTheme,
TextTheme textTheme,
bool centerTitle,
}) {
return AppBarTheme(
brightness: brightness ?? this.brightness,
......@@ -107,7 +109,7 @@ class AppBarTheme with Diagnosticable {
/// The [ThemeData.appBarTheme] property of the ambient [Theme].
static AppBarTheme of(BuildContext context) {
return Theme.of(context)!.appBarTheme;
return Theme.of(context).appBarTheme;
}
/// Linearly interpolate between two AppBar themes.
......@@ -115,7 +117,7 @@ class AppBarTheme with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
static AppBarTheme lerp(AppBarTheme a, AppBarTheme b, double t) {
assert(t != null);
return AppBarTheme(
brightness: t < 0.5 ? a?.brightness : b?.brightness,
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'debug.dart';
......@@ -25,7 +27,7 @@ import 'theme.dart';
class BackButtonIcon extends StatelessWidget {
/// Creates an icon that shows the appropriate "back" image for
/// the current platform (as obtained from the [Theme]).
const BackButtonIcon({ Key? key }) : super(key: key);
const BackButtonIcon({ Key key }) : super(key: key);
/// Returns the appropriate "back" icon for the given `platform`.
static IconData _getIconData(TargetPlatform platform) {
......@@ -39,10 +41,12 @@ class BackButtonIcon extends StatelessWidget {
case TargetPlatform.macOS:
return Icons.arrow_back_ios;
}
assert(false);
return null;
}
@override
Widget build(BuildContext context) => Icon(_getIconData(Theme.of(context)!.platform));
Widget build(BuildContext context) => Icon(_getIconData(Theme.of(context).platform));
}
/// A material design back button.
......@@ -74,13 +78,13 @@ class BackButtonIcon extends StatelessWidget {
class BackButton extends StatelessWidget {
/// Creates an [IconButton] with the appropriate "back" icon for the current
/// target platform.
const BackButton({ Key? key, this.color, this.onPressed }) : super(key: key);
const BackButton({ Key key, this.color, this.onPressed }) : super(key: key);
/// The color to use for the icon.
///
/// Defaults to the [IconThemeData.color] specified in the ambient [IconTheme],
/// which usually matches the ambient [Theme]'s [ThemeData.iconTheme].
final Color? color;
final Color color;
/// An override callback to perform instead of the default behavior which is
/// to pop the [Navigator].
......@@ -90,7 +94,7 @@ class BackButton extends StatelessWidget {
/// situations.
///
/// Defaults to null.
final VoidCallback? onPressed;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
......@@ -98,10 +102,10 @@ class BackButton extends StatelessWidget {
return IconButton(
icon: const BackButtonIcon(),
color: color,
tooltip: MaterialLocalizations.of(context)!.backButtonTooltip,
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () {
if (onPressed != null) {
onPressed!();
onPressed();
} else {
Navigator.maybePop(context);
}
......@@ -128,13 +132,13 @@ class BackButton extends StatelessWidget {
/// * [IconButton], to create other material design icon buttons.
class CloseButton extends StatelessWidget {
/// Creates a Material Design close button.
const CloseButton({ Key? key, this.color, this.onPressed }) : super(key: key);
const CloseButton({ Key key, this.color, this.onPressed }) : super(key: key);
/// The color to use for the icon.
///
/// Defaults to the [IconThemeData.color] specified in the ambient [IconTheme],
/// which usually matches the ambient [Theme]'s [ThemeData.iconTheme].
final Color? color;
final Color color;
/// An override callback to perform instead of the default behavior which is
/// to pop the [Navigator].
......@@ -144,7 +148,7 @@ class CloseButton extends StatelessWidget {
/// situations.
///
/// Defaults to null.
final VoidCallback? onPressed;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
......@@ -152,10 +156,10 @@ class CloseButton extends StatelessWidget {
return IconButton(
icon: const Icon(Icons.close),
color: color,
tooltip: MaterialLocalizations.of(context)!.closeButtonTooltip,
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
onPressed: () {
if (onPressed != null) {
onPressed!();
onPressed();
} else {
Navigator.maybePop(context);
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'banner_theme.dart';
......@@ -33,10 +35,10 @@ class MaterialBanner extends StatelessWidget {
/// The [actions], [content], and [forceActionsBelow] must be non-null.
/// The [actions.length] must be greater than 0.
const MaterialBanner({
Key? key,
required this.content,
Key key,
@required this.content,
this.contentTextStyle,
required this.actions,
@required this.actions,
this.leading,
this.backgroundColor,
this.padding,
......@@ -56,7 +58,7 @@ class MaterialBanner extends StatelessWidget {
///
/// If `null`, [MaterialBannerThemeData.contentTextStyle] is used. If that is
/// also `null`, [TextTheme.bodyText2] of [ThemeData.textTheme] is used.
final TextStyle? contentTextStyle;
final TextStyle contentTextStyle;
/// The set of actions that are displayed at the bottom or trailing side of
/// the [MaterialBanner].
......@@ -67,13 +69,13 @@ class MaterialBanner extends StatelessWidget {
/// The (optional) leading widget of the [MaterialBanner].
///
/// Typically an [Icon] widget.
final Widget? leading;
final Widget leading;
/// The color of the surface of this [MaterialBanner].
///
/// If `null`, [MaterialBannerThemeData.backgroundColor] is used. If that is
/// also `null`, [ColorScheme.surface] of [ThemeData.colorScheme] is used.
final Color? backgroundColor;
final Color backgroundColor;
/// The amount of space by which to inset the [content].
///
......@@ -82,12 +84,12 @@ class MaterialBanner extends StatelessWidget {
///
/// If the [actions] are trailing the [content], this defaults to
/// `EdgeInsetsDirectional.only(start: 16.0, top: 2.0)`.
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry padding;
/// The amount of space by which to inset the [leading] widget.
///
/// This defaults to `EdgeInsetsDirectional.only(end: 16.0)`.
final EdgeInsetsGeometry? leadingPadding;
final EdgeInsetsGeometry leadingPadding;
/// An override to force the [actions] to be below the [content] regardless of
/// how many there are.
......@@ -102,7 +104,7 @@ class MaterialBanner extends StatelessWidget {
Widget build(BuildContext context) {
assert(actions.isNotEmpty);
final ThemeData? theme = Theme.of(context);
final ThemeData theme = Theme.of(context);
final MaterialBannerThemeData bannerTheme = MaterialBannerTheme.of(context);
final bool isSingleRow = actions.length == 1 && !forceActionsBelow;
......@@ -125,10 +127,10 @@ class MaterialBanner extends StatelessWidget {
final Color backgroundColor = this.backgroundColor
?? bannerTheme.backgroundColor
?? theme!.colorScheme.surface;
final TextStyle? textStyle = contentTextStyle
?? theme.colorScheme.surface;
final TextStyle textStyle = contentTextStyle
?? bannerTheme.contentTextStyle
?? theme!.textTheme.bodyText2;
?? theme.textTheme.bodyText2;
return Container(
color: backgroundColor,
......
......@@ -2,6 +2,8 @@
// 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';
......@@ -36,25 +38,25 @@ class MaterialBannerThemeData with Diagnosticable {
});
/// The background color of a [MaterialBanner].
final Color? backgroundColor;
final Color backgroundColor;
/// Used to configure the [DefaultTextStyle] for the [MaterialBanner.content]
/// widget.
final TextStyle? contentTextStyle;
final TextStyle contentTextStyle;
/// The amount of space by which to inset [MaterialBanner.content].
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry padding;
/// The amount of space by which to inset [MaterialBanner.leading].
final EdgeInsetsGeometry? leadingPadding;
final EdgeInsetsGeometry leadingPadding;
/// Creates a copy of this object with the given fields replaced with the
/// new values.
MaterialBannerThemeData copyWith({
Color? backgroundColor,
TextStyle? contentTextStyle,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? leadingPadding,
Color backgroundColor,
TextStyle contentTextStyle,
EdgeInsetsGeometry padding,
EdgeInsetsGeometry leadingPadding,
}) {
return MaterialBannerThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -69,7 +71,7 @@ class MaterialBannerThemeData with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static MaterialBannerThemeData lerp(MaterialBannerThemeData? a, MaterialBannerThemeData? b, double t) {
static MaterialBannerThemeData lerp(MaterialBannerThemeData a, MaterialBannerThemeData b, double t) {
assert(t != null);
return MaterialBannerThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
......@@ -121,13 +123,13 @@ class MaterialBannerTheme extends InheritedTheme {
/// Creates a banner theme that controls the configurations for
/// [MaterialBanner]s in its widget subtree.
const MaterialBannerTheme({
Key? key,
Key key,
this.data,
required Widget child,
Widget child,
}) : super(key: key, child: child);
/// The properties for descendant [MaterialBanner] widgets.
final MaterialBannerThemeData? data;
final MaterialBannerThemeData data;
/// The closest instance of this class's [data] value that encloses the given
/// context.
......@@ -141,13 +143,13 @@ class MaterialBannerTheme extends InheritedTheme {
/// MaterialBannerThemeData theme = MaterialBannerTheme.of(context);
/// ```
static MaterialBannerThemeData of(BuildContext context) {
final MaterialBannerTheme? bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>();
return bannerTheme?.data ?? Theme.of(context)!.bannerTheme;
final MaterialBannerTheme bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>();
return bannerTheme?.data ?? Theme.of(context).bannerTheme;
}
@override
Widget wrap(BuildContext context, Widget child) {
final MaterialBannerTheme? ancestorTheme = context.findAncestorWidgetOfExactType<MaterialBannerTheme>();
final MaterialBannerTheme ancestorTheme = context.findAncestorWidgetOfExactType<MaterialBannerTheme>();
return identical(this, ancestorTheme) ? child : MaterialBannerTheme(data: data, child: child);
}
......
......@@ -2,6 +2,8 @@
// 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';
......@@ -48,7 +50,7 @@ class BottomAppBar extends StatefulWidget {
/// If the corresponding [BottomAppBarTheme] property is null, then the default
/// specified in the property's documentation will be used.
const BottomAppBar({
Key? key,
Key key,
this.color,
this.elevation,
this.shape,
......@@ -66,14 +68,14 @@ class BottomAppBar extends StatefulWidget {
///
/// Typically this the child will be a [Row], with the first child
/// being an [IconButton] with the [Icons.menu] icon.
final Widget? child;
final Widget child;
/// The bottom app bar's background color.
///
/// If this property is null then [BottomAppBarTheme.color] of
/// [ThemeData.bottomAppBarTheme] is used. If that's null then
/// [ThemeData.bottomAppBarColor] is used.
final Color? color;
final Color color;
/// The z-coordinate at which to place this bottom app bar relative to its
/// parent.
......@@ -84,14 +86,14 @@ class BottomAppBar extends StatefulWidget {
/// If this property is null then [BottomAppBarTheme.elevation] of
/// [ThemeData.bottomAppBarTheme] is used. If that's null, the default value
/// is 8.
final double? elevation;
final double elevation;
/// The notch that is made for the floating action button.
///
/// If this property is null then [BottomAppBarTheme.shape] of
/// [ThemeData.bottomAppBarTheme] is used. If that's null then the shape will
/// be rectangular with no notch.
final NotchedShape? shape;
final NotchedShape shape;
/// {@macro flutter.widgets.Clip}
///
......@@ -109,19 +111,19 @@ class BottomAppBar extends StatefulWidget {
}
class _BottomAppBarState extends State<BottomAppBar> {
late ValueListenable<ScaffoldGeometry> geometryListenable;
ValueListenable<ScaffoldGeometry> geometryListenable;
static const double _defaultElevation = 8.0;
@override
void didChangeDependencies() {
super.didChangeDependencies();
geometryListenable = Scaffold.geometryOf(context)!;
geometryListenable = Scaffold.geometryOf(context);
}
@override
Widget build(BuildContext context) {
final BottomAppBarTheme babTheme = BottomAppBarTheme.of(context);
final NotchedShape? notchedShape = widget.shape ?? babTheme.shape;
final NotchedShape notchedShape = widget.shape ?? babTheme.shape;
final CustomClipper<Path> clipper = notchedShape != null
? _BottomAppBarClipper(
geometry: geometryListenable,
......@@ -130,7 +132,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
)
: const ShapeBorderClipper(shape: RoundedRectangleBorder());
final double elevation = widget.elevation ?? babTheme.elevation ?? _defaultElevation;
final Color color = widget.color ?? babTheme.color ?? Theme.of(context)!.bottomAppBarColor;
final Color color = widget.color ?? babTheme.color ?? Theme.of(context).bottomAppBarColor;
final Color effectiveColor = ElevationOverlay.applyOverlay(context, color, elevation);
return PhysicalShape(
clipper: clipper,
......@@ -141,7 +143,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
type: MaterialType.transparency,
child: widget.child == null
? null
: SafeArea(child: widget.child!),
: SafeArea(child: widget.child),
),
);
}
......@@ -149,9 +151,9 @@ class _BottomAppBarState extends State<BottomAppBar> {
class _BottomAppBarClipper extends CustomClipper<Path> {
const _BottomAppBarClipper({
required this.geometry,
required this.shape,
required this.notchMargin,
@required this.geometry,
@required this.shape,
@required this.notchMargin,
}) : assert(geometry != null),
assert(shape != null),
assert(notchMargin != null),
......@@ -166,9 +168,9 @@ class _BottomAppBarClipper extends CustomClipper<Path> {
// button is the floating action button's bounding rectangle in the
// coordinate system whose origin is at the appBar's top left corner,
// or null if there is no floating action button.
final Rect? button = geometry.value.floatingActionButtonArea?.translate(
final Rect button = geometry.value.floatingActionButtonArea?.translate(
0.0,
geometry.value.bottomNavigationBarTop! * -1.0,
geometry.value.bottomNavigationBarTop * -1.0,
);
return shape.getOuterPath(Offset.zero & size, button?.inflate(notchMargin));
}
......
......@@ -2,6 +2,8 @@
// 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';
......@@ -37,20 +39,20 @@ class BottomAppBarTheme with Diagnosticable {
/// Default value for [BottomAppBar.color].
///
/// If null, [BottomAppBar] uses [ThemeData.bottomAppBarColor].
final Color? color;
final Color color;
/// Default value for [BottomAppBar.elevation].
final double? elevation;
final double elevation;
/// Default value for [BottomAppBar.shape].
final NotchedShape? shape;
final NotchedShape shape;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
BottomAppBarTheme copyWith({
Color? color,
double? elevation,
NotchedShape? shape,
Color color,
double elevation,
NotchedShape shape,
}) {
return BottomAppBarTheme(
color: color ?? this.color,
......@@ -61,7 +63,7 @@ class BottomAppBarTheme with Diagnosticable {
/// The [ThemeData.bottomAppBarTheme] property of the ambient [Theme].
static BottomAppBarTheme of(BuildContext context) {
return Theme.of(context)!.bottomAppBarTheme;
return Theme.of(context).bottomAppBarTheme;
}
/// Linearly interpolate between two BAB themes.
......@@ -69,7 +71,7 @@ class BottomAppBarTheme with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) {
static BottomAppBarTheme lerp(BottomAppBarTheme a, BottomAppBarTheme b, double t) {
assert(t != null);
return BottomAppBarTheme(
color: Color.lerp(a?.color, b?.color, t),
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -48,78 +50,78 @@ class BottomNavigationBarThemeData with Diagnosticable {
/// The color of the [BottomNavigationBar] itself.
///
/// See [BottomNavigationBar.backgroundColor].
final Color? backgroundColor;
final Color backgroundColor;
/// The z-coordinate of the [BottomNavigationBar].
///
/// See [BottomNavigationBar.elevation].
final double? elevation;
final double elevation;
/// The size, opacity, and color of the icon in the currently selected
/// [BottomNavigationBarItem.icon].
///
/// See [BottomNavigationBar.selectedIconTheme].
final IconThemeData? selectedIconTheme;
final IconThemeData selectedIconTheme;
/// The size, opacity, and color of the icon in the currently unselected
/// [BottomNavigationBarItem.icon]s.
///
/// See [BottomNavigationBar.unselectedIconTheme].
final IconThemeData? unselectedIconTheme;
final IconThemeData unselectedIconTheme;
/// The color of the selected [BottomNavigationBarItem.icon] and
/// [BottomNavigationBarItem.title].
///
/// See [BottomNavigationBar.selectedItemColor].
final Color? selectedItemColor;
final Color selectedItemColor;
/// The color of the unselected [BottomNavigationBarItem.icon] and
/// [BottomNavigationBarItem.title]s.
///
/// See [BottomNavigationBar.unselectedItemColor].
final Color? unselectedItemColor;
final Color unselectedItemColor;
/// The [TextStyle] of the [BottomNavigationBarItem] labels when they are
/// selected.
///
/// See [BottomNavigationBar.selectedLabelStyle].
final TextStyle? selectedLabelStyle;
final TextStyle selectedLabelStyle;
/// The [TextStyle] of the [BottomNavigationBarItem] labels when they are not
/// selected.
///
/// See [BottomNavigationBar.unselectedLabelStyle].
final TextStyle? unselectedLabelStyle;
final TextStyle unselectedLabelStyle;
/// Whether the labels are shown for the unselected [BottomNavigationBarItem]s.
///
/// See [BottomNavigationBar.showSelectedLabels].
final bool? showSelectedLabels;
final bool showSelectedLabels;
/// Whether the labels are shown for the selected [BottomNavigationBarItem].
///
/// See [BottomNavigationBar.showUnselectedLabels].
final bool? showUnselectedLabels;
final bool showUnselectedLabels;
/// Defines the layout and behavior of a [BottomNavigationBar].
///
/// See [BottomNavigationBar.type].
final BottomNavigationBarType? type;
final BottomNavigationBarType type;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
BottomNavigationBarThemeData copyWith({
Color? backgroundColor,
double? elevation,
IconThemeData? selectedIconTheme,
IconThemeData? unselectedIconTheme,
Color? selectedItemColor,
Color? unselectedItemColor,
TextStyle? selectedLabelStyle,
TextStyle? unselectedLabelStyle,
bool? showSelectedLabels,
bool? showUnselectedLabels,
BottomNavigationBarType? type,
Color backgroundColor,
double elevation,
IconThemeData selectedIconTheme,
IconThemeData unselectedIconTheme,
Color selectedItemColor,
Color unselectedItemColor,
TextStyle selectedLabelStyle,
TextStyle unselectedLabelStyle,
bool showSelectedLabels,
bool showUnselectedLabels,
BottomNavigationBarType type,
}) {
return BottomNavigationBarThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
......@@ -141,7 +143,7 @@ class BottomNavigationBarThemeData with Diagnosticable {
/// The argument `t` must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData? a, BottomNavigationBarThemeData? b, double t) {
static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData a, BottomNavigationBarThemeData b, double t) {
assert(t != null);
return BottomNavigationBarThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
......@@ -233,9 +235,9 @@ class BottomNavigationBarTheme extends InheritedWidget {
///
/// The [data] must not be null.
const BottomNavigationBarTheme({
Key? key,
required this.data,
required Widget child,
Key key,
@required this.data,
Widget child,
}) : assert(data != null), super(key: key, child: child);
/// The properties used for all descendant [BottomNavigationBar] widgets.
......@@ -252,8 +254,8 @@ class BottomNavigationBarTheme extends InheritedWidget {
/// BottomNavigationBarThemeData theme = BottomNavigationBarTheme.of(context);
/// ```
static BottomNavigationBarThemeData of(BuildContext context) {
final BottomNavigationBarTheme? bottomNavTheme = context.dependOnInheritedWidgetOfExactType<BottomNavigationBarTheme>();
return bottomNavTheme?.data ?? Theme.of(context)!.bottomNavigationBarTheme;
final BottomNavigationBarTheme bottomNavTheme = context.dependOnInheritedWidgetOfExactType<BottomNavigationBarTheme>();
return bottomNavTheme?.data ?? Theme.of(context).bottomNavigationBarTheme;
}
@override
......
......@@ -2,6 +2,8 @@
// 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/foundation.dart';
......@@ -49,8 +51,8 @@ class RawMaterialButton extends StatefulWidget {
/// [elevation], [focusElevation], [hoverElevation], [highlightElevation], and
/// [disabledElevation] must be non-negative.
const RawMaterialButton({
Key? key,
required this.onPressed,
Key key,
@required this.onPressed,
this.onLongPress,
this.onHighlightChanged,
this.mouseCursor,
......@@ -73,7 +75,7 @@ class RawMaterialButton extends StatefulWidget {
this.clipBehavior = Clip.none,
this.focusNode,
this.autofocus = false,
MaterialTapTargetSize? materialTapTargetSize,
MaterialTapTargetSize materialTapTargetSize,
this.child,
this.enableFeedback = true,
}) : materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded,
......@@ -97,7 +99,7 @@ class RawMaterialButton extends StatefulWidget {
/// See also:
///
/// * [enabled], which is true if the button is enabled.
final VoidCallback? onPressed;
final VoidCallback onPressed;
/// Called when the button is long-pressed.
///
......@@ -106,7 +108,7 @@ class RawMaterialButton extends StatefulWidget {
/// See also:
///
/// * [enabled], which is true if the button is enabled.
final VoidCallback? onLongPress;
final VoidCallback onLongPress;
/// Called by the underlying [InkWell] widget's [InkWell.onHighlightChanged]
/// callback.
......@@ -114,7 +116,7 @@ class RawMaterialButton extends StatefulWidget {
/// If [onPressed] changes from null to non-null while a gesture is ongoing,
/// this can fire during the build phase (in which case calling
/// [State.setState] is not allowed).
final ValueChanged<bool>? onHighlightChanged;
final ValueChanged<bool> onHighlightChanged;
/// {@template flutter.material.button.mouseCursor}
/// The cursor for a mouse pointer when it enters or is hovering over the
......@@ -130,7 +132,7 @@ class RawMaterialButton extends StatefulWidget {
///
/// If this property is null, [MaterialStateMouseCursor.clickable] will be used.
/// {@endtemplate}
final MouseCursor? mouseCursor;
final MouseCursor mouseCursor;
/// Defines the default text style, with [Material.textStyle], for the
/// button's [child].
......@@ -142,22 +144,22 @@ class RawMaterialButton extends StatefulWidget {
/// * [MaterialState.hovered].
/// * [MaterialState.focused].
/// * [MaterialState.disabled].
final TextStyle? textStyle;
final TextStyle textStyle;
/// The color of the button's [Material].
final Color? fillColor;
final Color fillColor;
/// The color for the button's [Material] when it has the input focus.
final Color? focusColor;
final Color focusColor;
/// The color for the button's [Material] when a pointer is hovering over it.
final Color? hoverColor;
final Color hoverColor;
/// The highlight color for the button's [InkWell].
final Color? highlightColor;
final Color highlightColor;
/// The splash color for the button's [InkWell].
final Color? splashColor;
final Color splashColor;
/// The elevation for the button's [Material] when the button
/// is [enabled] but not pressed.
......@@ -273,7 +275,7 @@ class RawMaterialButton extends StatefulWidget {
final Duration animationDuration;
/// Typically the button's label.
final Widget? child;
final Widget child;
/// Whether the button is enabled or disabled.
///
......@@ -291,7 +293,7 @@ class RawMaterialButton extends StatefulWidget {
final MaterialTapTargetSize materialTapTargetSize;
/// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode;
final FocusNode focusNode;
/// {@macro flutter.widgets.Focus.autofocus}
final bool autofocus;
......@@ -332,7 +334,7 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
setState(() {
_updateState(MaterialState.pressed, value);
if (widget.onHighlightChanged != null) {
widget.onHighlightChanged!(value);
widget.onHighlightChanged(value);
}
});
}
......@@ -393,11 +395,11 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
@override
Widget build(BuildContext context) {
final Color? effectiveTextColor = MaterialStateProperty.resolveAs<Color>(widget.textStyle?.color, _states);
final ShapeBorder? effectiveShape = MaterialStateProperty.resolveAs<ShapeBorder>(widget.shape, _states);
final Color effectiveTextColor = MaterialStateProperty.resolveAs<Color>(widget.textStyle?.color, _states);
final ShapeBorder effectiveShape = MaterialStateProperty.resolveAs<ShapeBorder>(widget.shape, _states);
final Offset densityAdjustment = widget.visualDensity.baseSizeAdjustment;
final BoxConstraints effectiveConstraints = widget.visualDensity.effectiveConstraints(widget.constraints);
final MouseCursor? effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
widget.mouseCursor ?? MaterialStateMouseCursor.clickable,
_states,
);
......@@ -485,9 +487,9 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
/// "tap target", but not its material or its ink splashes.
class _InputPadding extends SingleChildRenderObjectWidget {
const _InputPadding({
Key? key,
Widget? child,
required this.minSize,
Key key,
Widget child,
this.minSize,
}) : super(key: key, child: child);
final Size minSize;
......@@ -504,7 +506,7 @@ class _InputPadding extends SingleChildRenderObjectWidget {
}
class _RenderInputPadding extends RenderShiftedBox {
_RenderInputPadding(this._minSize, [RenderBox? child]) : super(child);
_RenderInputPadding(this._minSize, [RenderBox child]) : super(child);
Size get minSize => _minSize;
Size _minSize;
......@@ -518,57 +520,58 @@ class _RenderInputPadding extends RenderShiftedBox {
@override
double computeMinIntrinsicWidth(double height) {
if (child != null)
return math.max(child!.getMinIntrinsicWidth(height), minSize.width);
return math.max(child.getMinIntrinsicWidth(height), minSize.width);
return 0.0;
}
@override
double computeMinIntrinsicHeight(double width) {
if (child != null)
return math.max(child!.getMinIntrinsicHeight(width), minSize.height);
return math.max(child.getMinIntrinsicHeight(width), minSize.height);
return 0.0;
}
@override
double computeMaxIntrinsicWidth(double height) {
if (child != null)
return math.max(child!.getMaxIntrinsicWidth(height), minSize.width);
return math.max(child.getMaxIntrinsicWidth(height), minSize.width);
return 0.0;
}
@override
double computeMaxIntrinsicHeight(double width) {
if (child != null)
return math.max(child!.getMaxIntrinsicHeight(width), minSize.height);
return math.max(child.getMaxIntrinsicHeight(width), minSize.height);
return 0.0;
}
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child!.layout(constraints, parentUsesSize: true);
final double height = math.max(child!.size.width, minSize.width);
final double width = math.max(child!.size.height, minSize.height);
child.layout(constraints, parentUsesSize: true);
final double height = math.max(child.size.width, minSize.width);
final double width = math.max(child.size.height, minSize.height);
size = constraints.constrain(Size(height, width));
final BoxParentData childParentData = child!.parentData as BoxParentData;
childParentData.offset = Alignment.center.alongOffset(size - child!.size as Offset);
final BoxParentData childParentData = child.parentData as BoxParentData;
childParentData.offset = Alignment.center.alongOffset(size - child.size as Offset);
} else {
size = Size.zero;
}
}
@override
bool hitTest(BoxHitTestResult result, { required Offset position }) {
bool hitTest(BoxHitTestResult result, { Offset position }) {
if (super.hitTest(result, position: position)) {
return true;
}
final Offset center = child!.size.center(Offset.zero);
final Offset center = child.size.center(Offset.zero);
return result.addWithRawTransform(
transform: MatrixUtils.forceToPoint(center),
position: center,
hitTest: (BoxHitTestResult result, Offset? position) {
hitTest: (BoxHitTestResult result, Offset position) {
assert(position == center);
return child!.hitTest(result, position: center);
return child.hitTest(result, position: center);
},
);
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
......@@ -54,7 +56,7 @@ class ButtonBar extends StatelessWidget {
/// Both [buttonMinWidth] and [buttonHeight] must be non-negative if they
/// are not null.
const ButtonBar({
Key? key,
Key key,
this.alignment,
this.mainAxisSize,
this.buttonTextTheme,
......@@ -75,13 +77,13 @@ class ButtonBar extends StatelessWidget {
///
/// If null then it will use [ButtonBarThemeData.alignment]. If that is null,
/// it will default to [MainAxisAlignment.end].
final MainAxisAlignment? alignment;
final MainAxisAlignment alignment;
/// How much horizontal space is available. See [Row.mainAxisSize].
///
/// If null then it will use the surrounding [ButtonBarThemeData.mainAxisSize].
/// If that is null, it will default to [MainAxisSize.max].
final MainAxisSize? mainAxisSize;
final MainAxisSize mainAxisSize;
/// Overrides the surrounding [ButtonBarThemeData.buttonTextTheme] to define a
/// button's base colors, size, internal padding and shape.
......@@ -89,21 +91,21 @@ class ButtonBar extends StatelessWidget {
/// If null then it will use the surrounding
/// [ButtonBarThemeData.buttonTextTheme]. If that is null, it will default to
/// [ButtonTextTheme.primary].
final ButtonTextTheme? buttonTextTheme;
final ButtonTextTheme buttonTextTheme;
/// Overrides the surrounding [ButtonThemeData.minWidth] to define a button's
/// minimum width.
///
/// If null then it will use the surrounding [ButtonBarThemeData.buttonMinWidth].
/// If that is null, it will default to 64.0 logical pixels.
final double? buttonMinWidth;
final double buttonMinWidth;
/// Overrides the surrounding [ButtonThemeData.height] to define a button's
/// minimum height.
///
/// If null then it will use the surrounding [ButtonBarThemeData.buttonHeight].
/// If that is null, it will default to 36.0 logical pixels.
final double? buttonHeight;
final double buttonHeight;
/// Overrides the surrounding [ButtonThemeData.padding] to define the padding
/// for a button's child (typically the button's label).
......@@ -111,14 +113,14 @@ class ButtonBar extends StatelessWidget {
/// If null then it will use the surrounding [ButtonBarThemeData.buttonPadding].
/// If that is null, it will default to 8.0 logical pixels on the left
/// and right.
final EdgeInsetsGeometry? buttonPadding;
final EdgeInsetsGeometry buttonPadding;
/// Overrides the surrounding [ButtonThemeData.alignedDropdown] to define whether
/// a [DropdownButton] menu's width will match the button's width.
///
/// If null then it will use the surrounding [ButtonBarThemeData.buttonAlignedDropdown].
/// If that is null, it will default to false.
final bool? buttonAlignedDropdown;
final bool buttonAlignedDropdown;
/// Defines whether a [ButtonBar] should size itself with a minimum size
/// constraint or with padding.
......@@ -127,7 +129,7 @@ class ButtonBar extends StatelessWidget {
///
/// If null then it will use the surrounding [ButtonBarThemeData.layoutBehavior].
/// If that is null, it will default [ButtonBarLayoutBehavior.padded].
final ButtonBarLayoutBehavior? layoutBehavior;
final ButtonBarLayoutBehavior layoutBehavior;
/// Defines the vertical direction of a [ButtonBar]'s children if it
/// overflows.
......@@ -143,7 +145,7 @@ class ButtonBar extends StatelessWidget {
/// If null then it will use the surrounding
/// [ButtonBarThemeData.overflowDirection]. If that is null, it will
/// default to [VerticalDirection.down].
final VerticalDirection? overflowDirection;
final VerticalDirection overflowDirection;
/// The spacing between buttons when the button bar overflows.
///
......@@ -159,7 +161,7 @@ class ButtonBar extends StatelessWidget {
///
/// If null then no spacing will be added in between buttons in
/// an overflow state.
final double? overflowButtonSpacing;
final double overflowButtonSpacing;
/// The buttons to arrange horizontally.
///
......@@ -214,6 +216,8 @@ class ButtonBar extends StatelessWidget {
child: child,
);
}
assert(false);
return null;
}
}
......@@ -235,14 +239,14 @@ class _ButtonBarRow extends Flex {
/// Creates a button bar that attempts to display in a row, but displays in
/// a column if there is insufficient horizontal space.
_ButtonBarRow({
required List<Widget> children,
List<Widget> children,
Axis direction = Axis.horizontal,
MainAxisSize mainAxisSize = MainAxisSize.max,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection? textDirection,
TextDirection textDirection,
VerticalDirection overflowDirection = VerticalDirection.down,
TextBaseline? textBaseline,
TextBaseline textBaseline,
this.overflowButtonSpacing,
}) : super(
children: children,
......@@ -255,7 +259,7 @@ class _ButtonBarRow extends Flex {
textBaseline: textBaseline,
);
final double? overflowButtonSpacing;
final double overflowButtonSpacing;
@override
_RenderButtonBarRow createRenderObject(BuildContext context) {
......@@ -264,7 +268,7 @@ class _ButtonBarRow extends Flex {
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: mainAxisSize,
crossAxisAlignment: crossAxisAlignment,
textDirection: getEffectiveTextDirection(context)!,
textDirection: getEffectiveTextDirection(context),
verticalDirection: verticalDirection,
textBaseline: textBaseline,
overflowButtonSpacing: overflowButtonSpacing,
......@@ -303,14 +307,14 @@ class _RenderButtonBarRow extends RenderFlex {
/// Creates a button bar that attempts to display in a row, but displays in
/// a column if there is insufficient horizontal space.
_RenderButtonBarRow({
List<RenderBox>? children,
List<RenderBox> children,
Axis direction = Axis.horizontal,
MainAxisSize mainAxisSize = MainAxisSize.max,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
required TextDirection textDirection,
@required TextDirection textDirection,
VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline? textBaseline,
TextBaseline textBaseline,
this.overflowButtonSpacing,
}) : assert(textDirection != null),
assert(overflowButtonSpacing == null || overflowButtonSpacing >= 0),
......@@ -326,13 +330,13 @@ class _RenderButtonBarRow extends RenderFlex {
);
bool _hasCheckedLayoutWidth = false;
double? overflowButtonSpacing;
double overflowButtonSpacing;
@override
BoxConstraints get constraints {
if (_hasCheckedLayoutWidth)
return super.constraints;
return super.constraints.copyWith(maxWidth: double.infinity);
return super.constraints?.copyWith(maxWidth: double.infinity);
}
@override
......@@ -355,7 +359,7 @@ class _RenderButtonBarRow extends RenderFlex {
super.performLayout();
} else {
final BoxConstraints childConstraints = constraints.copyWith(minWidth: 0.0);
RenderBox? child;
RenderBox child;
double currentHeight = 0.0;
switch (verticalDirection) {
case VerticalDirection.down:
......@@ -377,7 +381,7 @@ class _RenderButtonBarRow extends RenderFlex {
// alignment for a row. For [MainAxisAlignment.spaceAround],
// [MainAxisAlignment.spaceBetween] and [MainAxisAlignment.spaceEvenly]
// cases, use [MainAxisAlignment.start].
switch (textDirection!) {
switch (textDirection) {
case TextDirection.ltr:
switch (mainAxisAlignment) {
case MainAxisAlignment.center:
......@@ -418,7 +422,7 @@ class _RenderButtonBarRow extends RenderFlex {
}
if (overflowButtonSpacing != null && child != null)
currentHeight += overflowButtonSpacing!;
currentHeight += overflowButtonSpacing;
}
size = constraints.constrain(Size(constraints.maxWidth, currentHeight));
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
......@@ -44,10 +46,10 @@ class ButtonBarThemeData with Diagnosticable {
assert(buttonHeight == null || buttonHeight >= 0.0);
/// How the children should be placed along the horizontal axis.
final MainAxisAlignment? alignment;
final MainAxisAlignment alignment;
/// How much horizontal space is available. See [Row.mainAxisSize].
final MainAxisSize? mainAxisSize;
final MainAxisSize mainAxisSize;
/// Defines a [ButtonBar] button's base colors, and the defaults for
/// the button's minimum size, internal padding, and shape.
......@@ -57,7 +59,7 @@ class ButtonBarThemeData with Diagnosticable {
///
/// Despite the name, this property is not a [TextTheme], its value is not a
/// collection of [TextStyle]s.
final ButtonTextTheme? buttonTextTheme;
final ButtonTextTheme buttonTextTheme;
/// The minimum width for [ButtonBar] buttons.
///
......@@ -66,19 +68,19 @@ class ButtonBarThemeData with Diagnosticable {
///
/// The actual horizontal space allocated for a button's child is
/// at least this value less the theme's horizontal [ButtonThemeData.padding].
final double? buttonMinWidth;
final double buttonMinWidth;
/// The minimum height for [ButtonBar] buttons.
///
/// This will override the surrounding [ButtonThemeData.height] setting
/// for buttons contained in the [ButtonBar].
final double? buttonHeight;
final double buttonHeight;
/// Padding for a [ButtonBar] button's child (typically the button's label).
///
/// This will override the surrounding [ButtonThemeData.padding] setting
/// for buttons contained in the [ButtonBar].
final EdgeInsetsGeometry? buttonPadding;
final EdgeInsetsGeometry buttonPadding;
/// If true, then a [DropdownButton] menu's width will match the [ButtonBar]
/// button's width.
......@@ -93,11 +95,11 @@ class ButtonBarThemeData with Diagnosticable {
///
/// This property only affects [DropdownButton] contained in a [ButtonBar]
/// and its menu.
final bool? buttonAlignedDropdown;
final bool buttonAlignedDropdown;
/// Defines whether a [ButtonBar] should size itself with a minimum size
/// constraint or with padding.
final ButtonBarLayoutBehavior? layoutBehavior;
final ButtonBarLayoutBehavior layoutBehavior;
/// Defines the vertical direction of a [ButtonBar]'s children if it
/// overflows.
......@@ -109,20 +111,20 @@ class ButtonBarThemeData with Diagnosticable {
/// the first action will be at the bottom of the column if this
/// property is set to [VerticalDirection.up], since it "starts" at the
/// bottom and "ends" at the top.
final VerticalDirection? overflowDirection;
final VerticalDirection overflowDirection;
/// Creates a copy of this object but with the given fields replaced with the
/// new values.
ButtonBarThemeData copyWith({
MainAxisAlignment? alignment,
MainAxisSize? mainAxisSize,
ButtonTextTheme? buttonTextTheme,
double? buttonMinWidth,
double? buttonHeight,
EdgeInsetsGeometry? buttonPadding,
bool? buttonAlignedDropdown,
ButtonBarLayoutBehavior? layoutBehavior,
VerticalDirection? overflowDirection,
MainAxisAlignment alignment,
MainAxisSize mainAxisSize,
ButtonTextTheme buttonTextTheme,
double buttonMinWidth,
double buttonHeight,
EdgeInsetsGeometry buttonPadding,
bool buttonAlignedDropdown,
ButtonBarLayoutBehavior layoutBehavior,
VerticalDirection overflowDirection,
}) {
return ButtonBarThemeData(
alignment: alignment ?? this.alignment,
......@@ -142,20 +144,20 @@ class ButtonBarThemeData with Diagnosticable {
/// If both arguments are null, then null is returned.
///
/// {@macro dart.ui.shadow.lerp}
static ButtonBarThemeData? lerp(ButtonBarThemeData? a, ButtonBarThemeData? b, double t) {
static ButtonBarThemeData lerp(ButtonBarThemeData a, ButtonBarThemeData b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
return ButtonBarThemeData(
alignment: t < 0.5 ? a?.alignment : b?.alignment,
mainAxisSize: t < 0.5 ? a?.mainAxisSize : b?.mainAxisSize,
buttonTextTheme: t < 0.5 ? a?.buttonTextTheme : b?.buttonTextTheme,
alignment: t < 0.5 ? a.alignment : b.alignment,
mainAxisSize: t < 0.5 ? a.mainAxisSize : b.mainAxisSize,
buttonTextTheme: t < 0.5 ? a.buttonTextTheme : b.buttonTextTheme,
buttonMinWidth: lerpDouble(a?.buttonMinWidth, b?.buttonMinWidth, t),
buttonHeight: lerpDouble(a?.buttonHeight, b?.buttonHeight, t),
buttonPadding: EdgeInsetsGeometry.lerp(a?.buttonPadding, b?.buttonPadding, t),
buttonAlignedDropdown: t < 0.5 ? a?.buttonAlignedDropdown : b?.buttonAlignedDropdown,
layoutBehavior: t < 0.5 ? a?.layoutBehavior : b?.layoutBehavior,
overflowDirection: t < 0.5 ? a?.overflowDirection : b?.overflowDirection,
buttonAlignedDropdown: t < 0.5 ? a.buttonAlignedDropdown : b.buttonAlignedDropdown,
layoutBehavior: t < 0.5 ? a.layoutBehavior : b.layoutBehavior,
overflowDirection: t < 0.5 ? a.overflowDirection : b.overflowDirection,
);
}
......@@ -233,9 +235,9 @@ class ButtonBarTheme extends InheritedWidget {
///
/// The [data] must not be null.
const ButtonBarTheme({
Key? key,
required this.data,
required Widget child,
Key key,
@required this.data,
Widget child,
}) : assert(data != null), super(key: key, child: child);
/// The properties used for all descendant [ButtonBar] widgets.
......@@ -251,8 +253,8 @@ class ButtonBarTheme extends InheritedWidget {
/// ButtonBarThemeData theme = ButtonBarTheme.of(context);
/// ```
static ButtonBarThemeData of(BuildContext context) {
final ButtonBarTheme? buttonBarTheme = context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>();
return buttonBarTheme?.data ?? Theme.of(context)!.buttonBarTheme;
final ButtonBarTheme buttonBarTheme = context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>();
return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme;
}
@override
......
......@@ -30,7 +30,7 @@ void main() {
expect(themeData.showUnselectedLabels, null);
expect(themeData.type, null);
const BottomNavigationBarTheme theme = BottomNavigationBarTheme(data: BottomNavigationBarThemeData(), child: SizedBox());
const BottomNavigationBarTheme theme = BottomNavigationBarTheme(data: BottomNavigationBarThemeData());
expect(theme.data.backgroundColor, null);
expect(theme.data.elevation, null);
expect(theme.data.selectedIconTheme, null);
......
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