Make Theme.of non-nullable (#68922)

This commit is contained in:
Michael Goderbauer 2020-11-02 09:20:42 -08:00 committed by GitHub
parent 3aba15f95d
commit 0490fd75aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
117 changed files with 279 additions and 294 deletions

View File

@ -384,16 +384,16 @@ class AboutDialog extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (icon != null) IconTheme(data: Theme.of(context)!.iconTheme, child: icon),
if (icon != null) IconTheme(data: Theme.of(context).iconTheme, child: icon),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: ListBody(
children: <Widget>[
Text(name, style: Theme.of(context)!.textTheme.headline5),
Text(version, style: Theme.of(context)!.textTheme.bodyText2),
Text(name, style: Theme.of(context).textTheme.headline5),
Text(version, style: Theme.of(context).textTheme.bodyText2),
const SizedBox(height: _textVerticalSeparation),
Text(applicationLegalese ?? '', style: Theme.of(context)!.textTheme.caption),
Text(applicationLegalese ?? '', style: Theme.of(context).textTheme.caption),
],
),
),
@ -551,26 +551,26 @@ class _AboutProgram extends StatelessWidget {
children: <Widget>[
Text(
name,
style: Theme.of(context)!.textTheme.headline5,
style: Theme.of(context).textTheme.headline5,
textAlign: TextAlign.center,
),
if (icon != null)
IconTheme(data: Theme.of(context)!.iconTheme, child: icon!),
IconTheme(data: Theme.of(context).iconTheme, child: icon!),
Text(
version,
style: Theme.of(context)!.textTheme.bodyText2,
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.center,
),
const SizedBox(height: _textVerticalSeparation),
Text(
legalese ?? '',
style: Theme.of(context)!.textTheme.caption,
style: Theme.of(context).textTheme.caption,
textAlign: TextAlign.center,
),
const SizedBox(height: _textVerticalSeparation),
Text(
'Powered by Flutter',
style: Theme.of(context)!.textTheme.bodyText2,
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.center,
),
],
@ -621,7 +621,7 @@ class _PackagesViewState extends State<_PackagesView> {
builder: (BuildContext context, int? selectedId, Widget? _) {
return Center(
child: Material(
color: Theme.of(context)!.cardColor,
color: Theme.of(context).cardColor,
elevation: 4.0,
child: Container(
constraints: BoxConstraints.loose(const Size.fromWidth(600.0)),
@ -633,7 +633,7 @@ class _PackagesViewState extends State<_PackagesView> {
);
default:
return Material(
color: Theme.of(context)!.cardColor,
color: Theme.of(context).cardColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
@ -717,7 +717,7 @@ class _PackageListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Ink(
color: isSelected ? Theme.of(context)!.highlightColor : Theme.of(context)!.cardColor,
color: isSelected ? Theme.of(context).highlightColor : Theme.of(context).cardColor,
child: ListTile(
title: Text(packageName),
subtitle: Text(MaterialLocalizations.of(context).licensesPackageDetailText(numberLicenses)),
@ -891,7 +891,7 @@ class _PackageLicensePageState extends State<_PackageLicensePage> {
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final ThemeData? theme = Theme.of(context);
final ThemeData theme = Theme.of(context);
final String title = widget.packageName;
final String subtitle = localizations.licensesPackageDetailText(widget.licenseEntries.length);
final double pad = _getGutterSize(context);
@ -914,7 +914,7 @@ class _PackageLicensePageState extends State<_PackageLicensePage> {
title: _PackageLicensePageTitle(
title,
subtitle,
theme!.appBarTheme.textTheme ?? theme.primaryTextTheme,
theme.appBarTheme.textTheme ?? theme.primaryTextTheme,
),
),
body: Center(
@ -941,7 +941,7 @@ class _PackageLicensePageState extends State<_PackageLicensePage> {
SliverAppBar(
automaticallyImplyLeading: false,
pinned: true,
backgroundColor: theme!.cardColor,
backgroundColor: theme.cardColor,
title: _PackageLicensePageTitle(title, subtitle, theme.textTheme),
),
SliverPadding(
@ -1540,7 +1540,7 @@ class _MasterDetailScaffoldState extends State<_MasterDetailScaffold>
constraints:
BoxConstraints.tightFor(width: masterViewWidth),
child: IconTheme(
data: Theme.of(context)!.primaryIconTheme,
data: Theme.of(context).primaryIconTheme,
child: ButtonBar(
children:
widget.actionBuilder!(context, _ActionLevel.view),
@ -1639,7 +1639,7 @@ class _DetailView extends StatelessWidget {
return MouseRegion(
// TODO(TonicArtos): Remove MouseRegion workaround for pointer hover events passing through DraggableScrollableSheet once https://github.com/flutter/flutter/issues/59741 is resolved.
child: Card(
color: Theme.of(context)!.cardColor,
color: Theme.of(context).cardColor,
elevation: _kCardElevation,
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.fromLTRB(

View File

@ -662,7 +662,7 @@ class MaterialApp extends StatefulWidget {
class _MaterialScrollBehavior extends ScrollBehavior {
@override
TargetPlatform getPlatform(BuildContext context) {
return Theme.of(context)!.platform;
return Theme.of(context).platform;
}
@override
@ -680,7 +680,7 @@ class _MaterialScrollBehavior extends ScrollBehavior {
return GlowingOverscrollIndicator(
child: child,
axisDirection: axisDirection,
color: Theme.of(context)!.accentColor,
color: Theme.of(context).accentColor,
);
}
}

View File

@ -498,7 +498,7 @@ class _AppBarState extends State<AppBar> {
Widget build(BuildContext context) {
assert(!widget.primary || debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData? theme = Theme.of(context);
final ThemeData theme = Theme.of(context);
final AppBarTheme appBarTheme = AppBarTheme.of(context);
final ScaffoldState? scaffold = Scaffold.maybeOf(context);
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
@ -512,16 +512,16 @@ class _AppBarState extends State<AppBar> {
IconThemeData overallIconTheme = widget.iconTheme
?? appBarTheme.iconTheme
?? theme!.primaryIconTheme;
?? theme.primaryIconTheme;
IconThemeData actionsIconTheme = widget.actionsIconTheme
?? appBarTheme.actionsIconTheme
?? overallIconTheme;
TextStyle? centerStyle = widget.textTheme?.headline6
?? appBarTheme.textTheme?.headline6
?? theme!.primaryTextTheme.headline6;
?? theme.primaryTextTheme.headline6;
TextStyle? sideStyle = widget.textTheme?.bodyText2
?? appBarTheme.textTheme?.bodyText2
?? theme!.primaryTextTheme.bodyText2;
?? theme.primaryTextTheme.bodyText2;
if (widget.toolbarOpacity != 1.0) {
final double opacity = const Interval(0.25, 1.0, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity);
@ -560,7 +560,7 @@ class _AppBarState extends State<AppBar> {
Widget? title = widget.title;
if (title != null) {
bool? namesRoute;
switch (theme!.platform) {
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
@ -632,7 +632,7 @@ class _AppBarState extends State<AppBar> {
leading: leading,
middle: title,
trailing: actions,
centerMiddle: widget._getEffectiveCenterTitle(theme!),
centerMiddle: widget._getEffectiveCenterTitle(theme),
middleSpacing: widget.titleSpacing ?? appBarTheme.titleSpacing ?? NavigationToolbar.kMiddleSpacing,
);

View File

@ -115,7 +115,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.

View File

@ -42,7 +42,7 @@ class BackButtonIcon extends StatelessWidget {
}
@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.

View File

@ -126,7 +126,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;
@ -149,10 +149,10 @@ class MaterialBanner extends StatelessWidget {
final Color backgroundColor = this.backgroundColor
?? bannerTheme.backgroundColor
?? theme!.colorScheme.surface;
?? theme.colorScheme.surface;
final TextStyle? textStyle = contentTextStyle
?? bannerTheme.contentTextStyle
?? theme!.textTheme.bodyText2;
?? theme.textTheme.bodyText2;
return Container(
color: backgroundColor,

View File

@ -142,7 +142,7 @@ class MaterialBannerTheme extends InheritedTheme {
/// ```
static MaterialBannerThemeData of(BuildContext context) {
final MaterialBannerTheme? bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>();
return bannerTheme?.data ?? Theme.of(context)!.bannerTheme;
return bannerTheme?.data ?? Theme.of(context).bannerTheme;
}
@override

View File

@ -130,7 +130,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,

View File

@ -61,7 +61,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.

View File

@ -823,7 +823,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
assert(localizations != null);
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context);
final TextStyle effectiveSelectedLabelStyle =

View File

@ -261,7 +261,7 @@ class BottomNavigationBarTheme extends InheritedWidget {
/// ```
static BottomNavigationBarThemeData of(BuildContext context) {
final BottomNavigationBarTheme? bottomNavTheme = context.dependOnInheritedWidgetOfExactType<BottomNavigationBarTheme>();
return bottomNavTheme?.data ?? Theme.of(context)!.bottomNavigationBarTheme;
return bottomNavTheme?.data ?? Theme.of(context).bottomNavigationBarTheme;
}
@override

View File

@ -248,7 +248,7 @@ class _BottomSheetState extends State<BottomSheet> {
@override
Widget build(BuildContext context) {
final BottomSheetThemeData bottomSheetTheme = Theme.of(context)!.bottomSheetTheme;
final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme;
final Color? color = widget.backgroundColor ?? bottomSheetTheme.backgroundColor;
final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? 0;
final ShapeBorder? shape = widget.shape ?? bottomSheetTheme.shape;
@ -340,7 +340,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
ParametricCurve<double> animationCurve = _modalBottomSheetCurve;
String _getRouteLabel(MaterialLocalizations localizations) {
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return '';
@ -477,7 +477,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
removeTop: true,
child: Builder(
builder: (BuildContext context) {
final BottomSheetThemeData sheetTheme = Theme.of(context)!.bottomSheetTheme;
final BottomSheetThemeData sheetTheme = Theme.of(context).bottomSheetTheme;
return _ModalBottomSheet<T>(
route: this,
backgroundColor: backgroundColor ?? sheetTheme.modalBackgroundColor ?? sheetTheme.backgroundColor,

View File

@ -252,7 +252,7 @@ class ButtonBarTheme extends InheritedWidget {
/// ```
static ButtonBarThemeData of(BuildContext context) {
final ButtonBarTheme? buttonBarTheme = context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>();
return buttonBarTheme?.data ?? Theme.of(context)!.buttonBarTheme;
return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme;
}
@override

View File

@ -227,7 +227,7 @@ class ButtonTheme extends InheritedTheme {
final ButtonTheme? inheritedButtonTheme = context.dependOnInheritedWidgetOfExactType<ButtonTheme>();
ButtonThemeData? buttonTheme = inheritedButtonTheme?.data;
if (buttonTheme?.colorScheme == null) { // if buttonTheme or buttonTheme.colorScheme is null
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
buttonTheme ??= theme.buttonTheme;
if (buttonTheme.colorScheme == null) {
buttonTheme = buttonTheme.copyWith(

View File

@ -192,7 +192,7 @@ class Card extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final CardTheme cardTheme = CardTheme.of(context);
return Semantics(

View File

@ -95,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.

View File

@ -239,9 +239,9 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData? themeData = Theme.of(context);
final ThemeData themeData = Theme.of(context);
Size size;
switch (widget.materialTapTargetSize ?? themeData!.materialTapTargetSize) {
switch (widget.materialTapTargetSize ?? themeData.materialTapTargetSize) {
case MaterialTapTargetSize.padded:
size = const Size(kMinInteractiveDimension, kMinInteractiveDimension);
break;
@ -249,7 +249,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
size = const Size(kMinInteractiveDimension - 8.0, kMinInteractiveDimension - 8.0);
break;
}
size += (widget.visualDensity ?? themeData!.visualDensity).baseSizeAdjustment;
size += (widget.visualDensity ?? themeData.visualDensity).baseSizeAdjustment;
final BoxConstraints additionalConstraints = BoxConstraints.tight(size);
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
widget.mouseCursor ?? MaterialStateMouseCursor.clickable,
@ -274,9 +274,9 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin {
return _CheckboxRenderObjectWidget(
value: widget.value,
tristate: widget.tristate,
activeColor: widget.activeColor ?? themeData!.toggleableActiveColor,
activeColor: widget.activeColor ?? themeData.toggleableActiveColor,
checkColor: widget.checkColor ?? const Color(0xFFFFFFFF),
inactiveColor: enabled ? themeData!.unselectedWidgetColor : themeData!.disabledColor,
inactiveColor: enabled ? themeData.unselectedWidgetColor : themeData.disabledColor,
focusColor: widget.focusColor ?? themeData.focusColor,
hoverColor: widget.hoverColor ?? themeData.hoverColor,
splashRadius: widget.splashRadius ?? kRadialReactionRadius,

View File

@ -432,7 +432,7 @@ class CheckboxListTile extends StatelessWidget {
}
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context)!.accentColor,
selectedColor: activeColor ?? Theme.of(context).accentColor,
child: ListTile(
leading: leading,
title: title,

View File

@ -1918,7 +1918,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
(MediaQuery.of(context).textScaleFactor - 1.0).clamp(0.0, 1.0),
)!;
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ChipThemeData chipTheme = ChipTheme.of(context);
final TextDirection? textDirection = Directionality.maybeOf(context);
final OutlinedBorder resolvedShape = _getShape(chipTheme);
@ -2985,7 +2985,7 @@ class _LocationAwareInkRippleFactory extends InteractiveInkFeatureFactory {
? deleteIconKey.currentContext!
: chipContext;
final InteractiveInkFeatureFactory splashFactory = Theme.of(splashContext)!.splashFactory;
final InteractiveInkFeatureFactory splashFactory = Theme.of(splashContext).splashFactory;
if (tapIsOnDeleteIcon) {
final RenderBox currentBox = referenceBox;

View File

@ -86,7 +86,7 @@ class ChipTheme extends InheritedTheme {
/// theme.
static ChipThemeData of(BuildContext context) {
final ChipTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>();
return inheritedTheme?.data ?? Theme.of(context)!.chipTheme;
return inheritedTheme?.data ?? Theme.of(context).chipTheme;
}
@override

View File

@ -174,7 +174,7 @@ class CircleAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
TextStyle textStyle = theme.primaryTextTheme.subtitle1!.copyWith(color: foregroundColor);
Color? effectiveBackgroundColor = backgroundColor;
if (effectiveBackgroundColor == null) {

View File

@ -698,7 +698,7 @@ class DataTable extends StatelessWidget {
required MaterialStateProperty<Color?>? overlayColor,
required bool tristate,
}) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final double effectiveHorizontalMargin = horizontalMargin
?? themeData.dataTableTheme.horizontalMargin
?? _horizontalMargin;
@ -745,7 +745,7 @@ class DataTable extends StatelessWidget {
required bool ascending,
required MaterialStateProperty<Color?>? overlayColor,
}) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
label = Row(
textDirection: numeric ? TextDirection.rtl : null,
children: <Widget>[
@ -807,7 +807,7 @@ class DataTable extends StatelessWidget {
required VoidCallback? onSelectChanged,
required MaterialStateProperty<Color?>? overlayColor,
}) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
if (showEditIcon) {
const Widget icon = Icon(Icons.edit, size: 18.0);
label = Expanded(child: label);
@ -854,7 +854,7 @@ class DataTable extends StatelessWidget {
Widget build(BuildContext context) {
assert(!_debugInteractive || debugCheckHasMaterial(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final MaterialStateProperty<Color?>? effectiveHeadingRowColor = headingRowColor
?? theme.dataTableTheme.headingRowColor;
final MaterialStateProperty<Color?>? effectiveDataRowColor = dataRowColor

View File

@ -241,7 +241,7 @@ class DataTableTheme extends InheritedWidget {
/// ```
static DataTableThemeData of(BuildContext context) {
final DataTableTheme? dataTableTheme = context.dependOnInheritedWidgetOfExactType<DataTableTheme>();
return dataTableTheme?.data ?? Theme.of(context)!.dataTableTheme;
return dataTableTheme?.data ?? Theme.of(context).dataTableTheme;
}
@override

View File

@ -143,7 +143,7 @@ class Dialog extends StatelessWidget {
child: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 280.0),
child: Material(
color: backgroundColor ?? dialogTheme.backgroundColor ?? Theme.of(context)!.dialogBackgroundColor,
color: backgroundColor ?? dialogTheme.backgroundColor ?? Theme.of(context).dialogBackgroundColor,
elevation: elevation ?? dialogTheme.elevation ?? _defaultElevation,
shape: shape ?? dialogTheme.shape ?? _defaultDialogShape,
type: MaterialType.card,
@ -451,7 +451,7 @@ class AlertDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final DialogTheme dialogTheme = DialogTheme.of(context);
String? label = semanticLabel;
@ -807,7 +807,7 @@ class SimpleDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
String? label = semanticLabel;
if (title == null) {

View File

@ -82,7 +82,7 @@ class DialogTheme with Diagnosticable {
/// The data from the closest [DialogTheme] instance given the build context.
static DialogTheme of(BuildContext context) {
return Theme.of(context)!.dialogTheme;
return Theme.of(context).dialogTheme;
}
/// Linearly interpolate between two dialog themes.

View File

@ -179,7 +179,7 @@ class Divider extends StatelessWidget {
/// {@end-tool}
static BorderSide createBorderSide(BuildContext? context, { Color? color, double? width }) {
final Color? effectiveColor = color
?? (context != null ? (DividerTheme.of(context).color ?? Theme.of(context)!.dividerColor) : null);
?? (context != null ? (DividerTheme.of(context).color ?? Theme.of(context).dividerColor) : null);
final double effectiveWidth = width
?? (context != null ? DividerTheme.of(context).thickness : null)
?? 0.0;

View File

@ -161,7 +161,7 @@ class DividerTheme extends InheritedTheme {
/// ```
static DividerThemeData of(BuildContext context) {
final DividerTheme? dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>();
return dividerTheme?.data ?? Theme.of(context)!.dividerTheme;
return dividerTheme?.data ?? Theme.of(context).dividerTheme;
}
@override

View File

@ -177,7 +177,7 @@ class Drawer extends StatelessWidget {
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
String? label = semanticLabel;
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
break;
@ -534,7 +534,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
}
} else {
final bool platformHasBackButton;
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
platformHasBackButton = true;
break;

View File

@ -75,7 +75,7 @@ class DrawerHeader extends StatelessWidget {
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
assert(debugCheckHasMediaQuery(context));
final ThemeData? theme = Theme.of(context);
final ThemeData theme = Theme.of(context);
final double statusBarHeight = MediaQuery.of(context).padding.top;
return Container(
height: statusBarHeight + _kDrawerHeaderHeight,
@ -91,7 +91,7 @@ class DrawerHeader extends StatelessWidget {
duration: duration,
curve: curve,
child: child == null ? null : DefaultTextStyle(
style: theme!.textTheme.bodyText1!,
style: theme.textTheme.bodyText1!,
child: MediaQuery.removePadding(
context: context,
removeTop: true,

View File

@ -94,7 +94,7 @@ class _DropdownScrollBehavior extends ScrollBehavior {
const _DropdownScrollBehavior();
@override
TargetPlatform getPlatform(BuildContext context) => Theme.of(context)!.platform;
TargetPlatform getPlatform(BuildContext context) => Theme.of(context).platform;
@override
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) => child;
@ -270,7 +270,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
opacity: _fadeOpacity,
child: CustomPaint(
painter: _DropdownMenuPainter(
color: widget.dropdownColor ?? Theme.of(context)!.canvasColor,
color: widget.dropdownColor ?? Theme.of(context).canvasColor,
elevation: route.elevation,
selectedIndex: route.selectedIndex,
resize: _resize,
@ -1175,7 +1175,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
}
}
TextStyle? get _textStyle => widget.style ?? Theme.of(context)!.textTheme.subtitle1;
TextStyle? get _textStyle => widget.style ?? Theme.of(context).textTheme.subtitle1;
void _handleTap() {
final RenderBox itemBox = context.findRenderObject()! as RenderBox;
@ -1239,7 +1239,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
// Similarly, we don't reduce the height of the button so much that its icon
// would be clipped.
double get _denseButtonHeight {
final double fontSize = _textStyle!.fontSize ?? Theme.of(context)!.textTheme.subtitle1!.fontSize!;
final double fontSize = _textStyle!.fontSize ?? Theme.of(context).textTheme.subtitle1!.fontSize!;
return math.max(fontSize, math.max(widget.iconSize, _kDenseButtonHeight));
}
@ -1249,7 +1249,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
if (widget.iconEnabledColor != null)
return widget.iconEnabledColor!;
switch (Theme.of(context)!.brightness) {
switch (Theme.of(context).brightness) {
case Brightness.light:
return Colors.grey.shade700;
case Brightness.dark:
@ -1259,7 +1259,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
if (widget.iconDisabledColor != null)
return widget.iconDisabledColor!;
switch (Theme.of(context)!.brightness) {
switch (Theme.of(context).brightness) {
case Brightness.light:
return Colors.grey.shade400;
case Brightness.dark:
@ -1318,7 +1318,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
hintIndex = items.length;
items.add(DefaultTextStyle(
style: _textStyle!.copyWith(color: Theme.of(context)!.hintColor),
style: _textStyle!.copyWith(color: Theme.of(context).hintColor),
child: IgnorePointer(
ignoringSemantics: false,
child: displayedHint,
@ -1355,7 +1355,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
child: Container(
decoration: _showHighlight
? BoxDecoration(
color: widget.focusColor ?? Theme.of(context)!.focusColor,
color: widget.focusColor ?? Theme.of(context).focusColor,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
)
: null,
@ -1502,7 +1502,7 @@ class DropdownButtonFormField<T> extends FormField<T> {
final _DropdownButtonFormFieldState<T> state = field as _DropdownButtonFormFieldState<T>;
final InputDecoration decorationArg = decoration ?? InputDecoration(focusColor: focusColor);
final InputDecoration effectiveDecoration = decorationArg.applyDefaults(
Theme.of(field.context)!.inputDecorationTheme,
Theme.of(field.context).inputDecorationTheme,
);
// An unfocusable Focus widget so that this widget can detect if its
// descendants have focus or not.

View File

@ -248,7 +248,7 @@ class ElevatedButton extends ButtonStyleButton {
/// * `3 < textScaleFactor` - horizontal(4)
@override
ButtonStyle defaultStyleOf(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding(

View File

@ -111,7 +111,7 @@ class ElevatedButtonTheme extends InheritedTheme {
/// ```
static ElevatedButtonThemeData of(BuildContext context) {
final ElevatedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<ElevatedButtonTheme>();
return buttonTheme?.data ?? Theme.of(context)!.elevatedButtonTheme;
return buttonTheme?.data ?? Theme.of(context).elevatedButtonTheme;
}
@override

View File

@ -43,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 &&
@ -61,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

View File

@ -155,7 +155,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
return widget.color!;
}
switch(Theme.of(context)!.brightness) {
switch(Theme.of(context).brightness) {
case Brightness.light:
return Colors.black54;
case Brightness.dark:

View File

@ -253,7 +253,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
@override
void didChangeDependencies() {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
_borderColorTween.end = theme.dividerColor;
_headerColorTween
..begin = theme.textTheme.subtitle1!.color

View File

@ -167,5 +167,5 @@ class Feedback {
};
}
static TargetPlatform _platform(BuildContext context) => Theme.of(context)!.platform;
static TargetPlatform _platform(BuildContext context) => Theme.of(context).platform;
}

View File

@ -205,7 +205,7 @@ class FlatButton extends MaterialButton {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ButtonThemeData buttonTheme = ButtonTheme.of(context);
return RawMaterialButton(
onPressed: onPressed,

View File

@ -339,7 +339,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
// title
if (widget.title != null) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
Widget? title;
switch (theme.platform) {

View File

@ -425,7 +425,7 @@ class FloatingActionButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme;
// Applications should no longer use accentIconTheme's color to configure

View File

@ -67,7 +67,7 @@ class GridTileBar extends StatelessWidget {
end: trailing != null ? 8.0 : 16.0,
);
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
accentColor: theme.accentColor,

View File

@ -326,7 +326,7 @@ class IconButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
Color? currentColor;
if (onPressed != null)
currentColor = color;

View File

@ -803,11 +803,11 @@ class _InkResponseState extends State<_InkResponseStateWidget>
// Material Design spec. A separate highlight is no longer used.
// See https://material.io/design/interaction/states.html#pressed
case _HighlightType.pressed:
return widget.highlightColor ?? Theme.of(context)!.highlightColor;
return widget.highlightColor ?? Theme.of(context).highlightColor;
case _HighlightType.focus:
return widget.overlayColor?.resolve(focused) ?? widget.focusColor ?? Theme.of(context)!.focusColor;
return widget.overlayColor?.resolve(focused) ?? widget.focusColor ?? Theme.of(context).focusColor;
case _HighlightType.hover:
return widget.overlayColor?.resolve(hovered) ?? widget.hoverColor ?? Theme.of(context)!.hoverColor;
return widget.overlayColor?.resolve(hovered) ?? widget.hoverColor ?? Theme.of(context).hoverColor;
}
}
@ -878,7 +878,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
final RenderBox referenceBox = context.findRenderObject()! as RenderBox;
final Offset position = referenceBox.globalToLocal(globalPosition);
const Set<MaterialState> pressed = <MaterialState>{MaterialState.pressed};
final Color color = widget.overlayColor?.resolve(pressed) ?? widget.splashColor ?? Theme.of(context)!.splashColor;
final Color color = widget.overlayColor?.resolve(pressed) ?? widget.splashColor ?? Theme.of(context).splashColor;
final RectCallback? rectCallback = widget.containedInkWell ? widget.getRectCallback!(referenceBox) : null;
final BorderRadius? borderRadius = widget.borderRadius;
final ShapeBorder? customBorder = widget.customBorder;
@ -894,7 +894,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
} // else we're probably in deactivate()
}
splash = (widget.splashFactory ?? Theme.of(context)!.splashFactory).create(
splash = (widget.splashFactory ?? Theme.of(context).splashFactory).create(
controller: inkController,
referenceBox: referenceBox,
position: position,
@ -1078,7 +1078,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
}
const Set<MaterialState> pressed = <MaterialState>{MaterialState.pressed};
_currentSplash?.color = widget.overlayColor?.resolve(pressed) ?? widget.splashColor ?? Theme.of(context)!.splashColor;
_currentSplash?.color = widget.overlayColor?.resolve(pressed) ?? widget.splashColor ?? Theme.of(context).splashColor;
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
widget.mouseCursor ?? MaterialStateMouseCursor.clickable,

View File

@ -1956,7 +1956,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
InputDecoration? _effectiveDecoration;
InputDecoration? get decoration {
_effectiveDecoration ??= widget.decoration.applyDefaults(
Theme.of(context)!.inputDecorationTheme,
Theme.of(context).inputDecorationTheme,
);
return _effectiveDecoration;
}
@ -2143,7 +2143,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextStyle inlineStyle = _getInlineStyle(themeData);
final TextBaseline textBaseline = inlineStyle.textBaseline!;

View File

@ -1025,7 +1025,7 @@ class ListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ListTileTheme tileTheme = ListTileTheme.of(context);
IconThemeData? iconThemeData;

View File

@ -338,7 +338,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
final GlobalKey _inkFeatureRenderer = GlobalKey(debugLabel: 'ink renderer');
Color? _getBackgroundColor(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
Color? color = widget.color;
if (color == null) {
switch (widget.type) {
@ -368,7 +368,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
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,
);
@ -406,7 +406,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
borderRadius: BorderRadius.zero,
elevation: widget.elevation,
color: ElevationOverlay.applyOverlay(context, backgroundColor!, widget.elevation),
shadowColor: widget.shadowColor ?? Theme.of(context)!.shadowColor,
shadowColor: widget.shadowColor ?? Theme.of(context).shadowColor,
animateColor: false,
child: contents,
);
@ -431,7 +431,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
clipBehavior: widget.clipBehavior,
elevation: widget.elevation,
color: backgroundColor!,
shadowColor: widget.shadowColor ?? Theme.of(context)!.shadowColor,
shadowColor: widget.shadowColor ?? Theme.of(context).shadowColor,
child: contents,
);
}

View File

@ -399,7 +399,7 @@ class MaterialButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ButtonThemeData buttonTheme = ButtonTheme.of(context);
return RawMaterialButton(

View File

@ -536,7 +536,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
widgets.add(
Container(
decoration: BoxDecoration(
color: Theme.of(context)!.cardColor,
color: Theme.of(context).cardColor,
borderRadius: _borderRadius(i - 1, widgets.isEmpty, false),
shape: BoxShape.rectangle,
),
@ -606,7 +606,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
widgets.add(
Container(
decoration: BoxDecoration(
color: Theme.of(context)!.cardColor,
color: Theme.of(context).cardColor,
borderRadius: _borderRadius(i - 1, widgets.isEmpty, true),
shape: BoxShape.rectangle,
),

View File

@ -431,7 +431,7 @@ class _NavigationRailState extends State<NavigationRail> with TickerProviderStat
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final NavigationRailThemeData navigationRailTheme = NavigationRailTheme.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
@ -726,7 +726,7 @@ class _RailDestination extends StatelessWidget {
break;
}
final ColorScheme colors = Theme.of(context)!.colorScheme;
final ColorScheme colors = Theme.of(context).colorScheme;
return Semantics(
container: true,
selected: selected,

View File

@ -202,7 +202,7 @@ class NavigationRailTheme extends InheritedTheme {
/// ```
static NavigationRailThemeData of(BuildContext context) {
final NavigationRailTheme? navigationRailTheme = context.dependOnInheritedWidgetOfExactType<NavigationRailTheme>();
return navigationRailTheme?.data ?? Theme.of(context)!.navigationRailTheme;
return navigationRailTheme?.data ?? Theme.of(context).navigationRailTheme;
}
@override

View File

@ -446,7 +446,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
Color _getFillColor() {
if (widget.highlightElevation == null || widget.highlightElevation == 0.0)
return Colors.transparent;
final Color color = widget.color ?? Theme.of(context)!.canvasColor;
final Color color = widget.color ?? Theme.of(context).canvasColor;
final Tween<Color?> colorTween = ColorTween(
begin: color.withAlpha(0x00),
end: color.withAlpha(0xFF),
@ -470,7 +470,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
if (widget.borderSide?.style == BorderStyle.none)
return widget.borderSide!;
final Color themeColor = Theme.of(context)!.colorScheme.onSurface.withOpacity(0.12);
final Color themeColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.12);
return BorderSide(
color: _outlineColor ?? themeColor,
@ -489,7 +489,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
return AnimatedBuilder(
animation: _controller,

View File

@ -219,7 +219,7 @@ class OutlinedButton extends ButtonStyleButton {
/// * `enableFeedback` - true
@override
ButtonStyle defaultStyleOf(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding(
@ -239,7 +239,7 @@ class OutlinedButton extends ButtonStyleButton {
padding: scaledPadding,
minimumSize: const Size(64, 36),
side: BorderSide(
color: Theme.of(context)!.colorScheme.onSurface.withOpacity(0.12),
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.12),
width: 1,
),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),

View File

@ -111,7 +111,7 @@ class OutlinedButtonTheme extends InheritedTheme {
/// ```
static OutlinedButtonThemeData of(BuildContext context) {
final OutlinedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<OutlinedButtonTheme>();
return buttonTheme?.data ?? Theme.of(context)!.outlinedButtonTheme;
return buttonTheme?.data ?? Theme.of(context).outlinedButtonTheme;
}
@override

View File

@ -123,7 +123,7 @@ mixin MaterialRouteTransitionMixin<T> on PageRoute<T> {
@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
final PageTransitionsTheme theme = Theme.of(context)!.pageTransitionsTheme;
final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme;
return theme.buildTransitions<T>(this, context, animation, secondaryAnimation, child);
}
}

View File

@ -589,7 +589,7 @@ class PageTransitionsTheme with Diagnosticable {
Animation<double> secondaryAnimation,
Widget child,
) {
TargetPlatform platform = Theme.of(context)!.platform;
TargetPlatform platform = Theme.of(context).platform;
if (CupertinoRouteTransitionMixin.isPopGestureInProgress(route))
platform = TargetPlatform.iOS;

View File

@ -332,7 +332,7 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
Widget build(BuildContext context) {
// TODO(ianh): This whole build function doesn't handle RTL yet.
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
// HEADER
final List<Widget> headerWidgets = <Widget>[];

View File

@ -196,7 +196,7 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
}
void _vibrate() {
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
@ -369,8 +369,8 @@ class _DatePickerModeToggleButtonState extends State<_DatePickerModeToggleButton
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context)!.colorScheme;
final TextTheme textTheme = Theme.of(context)!.textTheme;
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TextTheme textTheme = Theme.of(context).textTheme;
final Color controlColor = colorScheme.onSurface.withOpacity(0.60);
return Container(
@ -742,7 +742,7 @@ class _MonthPickerState extends State<_MonthPicker> {
Widget build(BuildContext context) {
final String previousTooltipText = '${_localizations.previousMonthTooltip} ${_localizations.formatMonthYear(_previousMonthDate)}';
final String nextTooltipText = '${_localizations.nextMonthTooltip} ${_localizations.formatMonthYear(_nextMonthDate)}';
final Color controlColor = Theme.of(context)!.colorScheme.onSurface.withOpacity(0.60);
final Color controlColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.60);
return Semantics(
child: Column(
@ -940,9 +940,9 @@ class _DayPickerState extends State<_DayPicker> {
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context)!.colorScheme;
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final TextTheme textTheme = Theme.of(context)!.textTheme;
final TextTheme textTheme = Theme.of(context).textTheme;
final TextStyle? headerStyle = textTheme.caption?.apply(
color: colorScheme.onSurface.withOpacity(0.60),
);
@ -1143,8 +1143,8 @@ class _YearPickerState extends State<_YearPicker> {
}
Widget _buildYearItem(BuildContext context, int index) {
final ColorScheme colorScheme = Theme.of(context)!.colorScheme;
final TextTheme textTheme = Theme.of(context)!.textTheme;
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TextTheme textTheme = Theme.of(context).textTheme;
// Backfill the _YearPicker with disabled years if necessary.
final int offset = _itemCount < minYears ? (minYears - _itemCount) ~/ 2 : 0;

View File

@ -135,7 +135,7 @@ class _CalendarDateRangePickerState extends State<CalendarDateRangePicker> {
int get _numberOfMonths => utils.monthDelta(widget.firstDate, widget.lastDate) + 1;
void _vibrate() {
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
HapticFeedback.vibrate();
@ -424,7 +424,7 @@ class _DayHeaders extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final ColorScheme colorScheme = themeData.colorScheme;
final TextStyle textStyle = themeData.textTheme.subtitle2!.apply(color: colorScheme.onSurface);
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
@ -676,7 +676,7 @@ class _MonthItemState extends State<_MonthItem> {
}
Color _highlightColor(BuildContext context) {
return Theme.of(context)!.colorScheme.primary.withOpacity(0.12);
return Theme.of(context).colorScheme.primary.withOpacity(0.12);
}
void _dayFocusChanged(bool focused) {
@ -703,7 +703,7 @@ class _MonthItemState extends State<_MonthItem> {
}
Widget _buildDayItem(BuildContext context, DateTime dayToBuild, int firstDayOffset, int daysInMonth) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final TextTheme textTheme = theme.textTheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
@ -816,7 +816,7 @@ class _MonthItemState extends State<_MonthItem> {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final int year = widget.displayedMonth.year;

View File

@ -238,7 +238,7 @@ class DayPicker extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final int year = displayedMonth.year;
final int month = displayedMonth.month;
@ -686,7 +686,7 @@ class _YearPickerState extends State<YearPicker> {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextStyle? style = themeData.textTheme.bodyText2;
return ListView.builder(
dragStartBehavior: widget.dragStartBehavior,

View File

@ -357,7 +357,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final Orientation orientation = MediaQuery.of(context).orientation;

View File

@ -91,7 +91,7 @@ class DatePickerHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final TextTheme textTheme = theme.textTheme;

View File

@ -413,7 +413,7 @@ class _DateRangePickerDialogState extends State<_DateRangePickerDialog> {
cancelText: widget.cancelText ?? localizations.cancelButtonLabel,
helpText: widget.helpText ?? localizations.dateRangePickerHelpText,
);
final DialogTheme dialogTheme = Theme.of(context)!.dialogTheme;
final DialogTheme dialogTheme = Theme.of(context).dialogTheme;
size = orientation == Orientation.portrait ? _inputPortraitDialogSize : _inputLandscapeDialogSize;
insetPadding = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0);
shape = dialogTheme.shape;
@ -476,7 +476,7 @@ class _CalendarRangePickerDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final Orientation orientation = MediaQuery.of(context).orientation;
@ -630,7 +630,7 @@ class _InputDateRangePickerDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final Orientation orientation = MediaQuery.of(context).orientation;

View File

@ -220,7 +220,7 @@ class _InputDatePickerFormFieldState extends State<InputDatePickerFormField> {
@override
Widget build(BuildContext context) {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final InputDecorationTheme inputTheme = Theme.of(context)!.inputDecorationTheme;
final InputDecorationTheme inputTheme = Theme.of(context).inputDecorationTheme;
return TextFormField(
decoration: InputDecoration(
border: inputTheme.border ?? const UnderlineInputBorder(),

View File

@ -226,7 +226,7 @@ class InputDateRangePickerState extends State<InputDateRangePicker> {
@override
Widget build(BuildContext context) {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final InputDecorationTheme inputTheme = Theme.of(context)!.inputDecorationTheme;
final InputDecorationTheme inputTheme = Theme.of(context).inputDecorationTheme;
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[

View File

@ -306,7 +306,7 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
TextStyle style = widget.textStyle ?? popupMenuTheme.textStyle ?? theme.textTheme.subtitle1!;
@ -522,7 +522,7 @@ class _PopupMenu<T> extends StatelessWidget {
Widget item = route.items[i];
if (route.initialValue != null && route.items[i].represents(route.initialValue)) {
item = Container(
color: Theme.of(context)!.highlightColor,
color: Theme.of(context).highlightColor,
child: item,
);
}
@ -831,7 +831,7 @@ Future<T?> showMenu<T>({
assert(items != null && items.isNotEmpty);
assert(debugCheckHasMaterialLocalizations(context));
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
break;
@ -1122,7 +1122,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
);
return IconButton(
icon: widget.icon ?? _getIcon(Theme.of(context)!.platform),
icon: widget.icon ?? _getIcon(Theme.of(context).platform),
padding: widget.padding,
tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
onPressed: widget.enabled ? showButtonMenu : null,

View File

@ -147,7 +147,7 @@ class PopupMenuTheme extends InheritedTheme {
/// ```
static PopupMenuThemeData of(BuildContext context) {
final PopupMenuTheme? popupMenuTheme = context.dependOnInheritedWidgetOfExactType<PopupMenuTheme>();
return popupMenuTheme?.data ?? Theme.of(context)!.popupMenuTheme;
return popupMenuTheme?.data ?? Theme.of(context).popupMenuTheme;
}
@override

View File

@ -109,8 +109,8 @@ abstract class ProgressIndicator extends StatefulWidget {
/// {@endtemplate}
final String? semanticsValue;
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context)!.backgroundColor;
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context)!.accentColor;
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
@ -595,7 +595,7 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> w
return _buildMaterialIndicator(context, 0.0, 0.0, 0, 0.0);
return _buildAnimation();
case _ActivityIndicatorType.adaptive:
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.iOS:
@ -739,7 +739,7 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
margin: const EdgeInsets.all(4.0), // accommodate the shadow
child: Material(
type: MaterialType.circle,
color: widget.backgroundColor ?? Theme.of(context)!.canvasColor,
color: widget.backgroundColor ?? Theme.of(context).canvasColor,
elevation: 2.0,
child: Padding(
padding: const EdgeInsets.all(12.0),

View File

@ -335,7 +335,7 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
Size size;
switch (widget.materialTapTargetSize ?? themeData.materialTapTargetSize) {
case MaterialTapTargetSize.padded:

View File

@ -520,7 +520,7 @@ class RadioListTile<T> extends StatelessWidget {
}
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context)!.accentColor,
selectedColor: activeColor ?? Theme.of(context).accentColor,
child: ListTile(
leading: leading,
title: title,

View File

@ -227,7 +227,7 @@ class RaisedButton extends MaterialButton {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ButtonThemeData buttonTheme = ButtonTheme.of(context);
return RawMaterialButton(
onPressed: onPressed,

View File

@ -575,7 +575,7 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
assert(debugCheckHasMaterial(context));
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
SliderThemeData sliderTheme = SliderTheme.of(context);
// If the widget has active or inactive colors specified, then we plug them
@ -722,7 +722,7 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
state: state,
textDirection: Directionality.of(context),
semanticFormatterCallback: semanticFormatterCallback,
platform: Theme.of(context)!.platform,
platform: Theme.of(context).platform,
);
}
@ -743,7 +743,7 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
..onChangeEnd = onChangeEnd
..textDirection = Directionality.of(context)
..semanticFormatterCallback = semanticFormatterCallback
..platform = Theme.of(context)!.platform;
..platform = Theme.of(context).platform;
}
}

View File

@ -196,11 +196,11 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
@override
void didChangeDependencies() {
final ThemeData? theme = Theme.of(context);
final ThemeData theme = Theme.of(context);
_valueColor = _positionController.drive(
ColorTween(
begin: (widget.color ?? theme!.accentColor).withOpacity(0.0),
end: (widget.color ?? theme!.accentColor).withOpacity(1.0),
begin: (widget.color ?? theme.accentColor).withOpacity(0.0),
end: (widget.color ?? theme.accentColor).withOpacity(1.0),
).chain(CurveTween(
curve: const Interval(0.0, 1.0 / _kDragSizeFactorLimit)
)),

View File

@ -2907,7 +2907,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasDirectionality(context));
final MediaQueryData mediaQuery = MediaQuery.of(context);
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextDirection textDirection = Directionality.of(context);
// TODO(Piinks): Remove old SnackBar API after migrating ScaffoldMessenger

View File

@ -106,7 +106,7 @@ class _ScrollbarState extends State<Scrollbar> with SingleTickerProviderStateMix
@override
void didChangeDependencies() {
super.didChangeDependencies();
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:

View File

@ -196,7 +196,7 @@ abstract class SearchDelegate<T> {
/// * [AppBar.brightness], which is set to [ThemeData.primaryColorBrightness].
ThemeData appBarTheme(BuildContext context) {
assert(context != null);
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
assert(theme != null);
return theme.copyWith(
primaryColor: theme.brightness == Brightness.dark

View File

@ -82,7 +82,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur
void onSingleTapUp(TapUpDetails details) {
editableText.hideToolbar();
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context)!.platform) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
renderEditable.selectWordEdge(cause: SelectionChangedCause.tap);
@ -507,7 +507,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
widget.onSelectionChanged!(selection, cause);
}
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
if (cause == SelectionChangedCause.longPress) {
@ -567,7 +567,7 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
'inherit false style must supply fontSize and textBaseline',
);
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context);
final FocusNode focusNode = _effectiveFocusNode;

View File

@ -620,7 +620,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
return _buildMaterialSlider(context);
case _SliderType.adaptive: {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.android:
@ -637,7 +637,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
}
Widget _buildMaterialSlider(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
SliderThemeData sliderTheme = SliderTheme.of(context);
// If the widget has active or inactive colors specified, then we plug them
@ -827,7 +827,7 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
state: state,
textDirection: Directionality.of(context),
semanticFormatterCallback: semanticFormatterCallback,
platform: Theme.of(context)!.platform,
platform: Theme.of(context).platform,
hasFocus: hasFocus,
hovering: hovering,
);
@ -849,7 +849,7 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
..onChangeEnd = onChangeEnd
..textDirection = Directionality.of(context)
..semanticFormatterCallback = semanticFormatterCallback
..platform = Theme.of(context)!.platform
..platform = Theme.of(context).platform
..hasFocus = hasFocus
..hovering = hovering;
// Ticker provider cannot change since there's a 1:1 relationship between

View File

@ -112,7 +112,7 @@ class SliderTheme extends InheritedTheme {
/// theme.
static SliderThemeData of(BuildContext context) {
final SliderTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<SliderTheme>();
return inheritedTheme != null ? inheritedTheme.data : Theme.of(context)!.sliderTheme;
return inheritedTheme != null ? inheritedTheme.data : Theme.of(context).sliderTheme;
}
@override

View File

@ -129,7 +129,7 @@ class _SnackBarActionState extends State<SnackBarAction> {
@override
Widget build(BuildContext context) {
Color? resolveForegroundColor(Set<MaterialState> states) {
final SnackBarThemeData snackBarTheme = Theme.of(context)!.snackBarTheme;
final SnackBarThemeData snackBarTheme = Theme.of(context).snackBarTheme;
if (states.contains(MaterialState.disabled))
return widget.disabledTextColor ?? snackBarTheme.disabledActionTextColor;
return widget.textColor ?? snackBarTheme.actionTextColor;
@ -385,7 +385,7 @@ class _SnackBarState extends State<SnackBar> {
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;

View File

@ -281,7 +281,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
}
bool _isDark() {
return Theme.of(context)!.brightness == Brightness.dark;
return Theme.of(context).brightness == Brightness.dark;
}
Widget _buildLine(bool visible) {
@ -321,7 +321,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
}
Color _circleColor(int index) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
if (!_isDark()) {
return widget.steps[index].isActive ? themeData.primaryColor : Colors.black38;
} else {
@ -395,7 +395,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
return widget.controlsBuilder!(context, onStepContinue: widget.onStepContinue, onStepCancel: widget.onStepCancel);
final Color cancelColor;
switch (Theme.of(context)!.brightness) {
switch (Theme.of(context).brightness) {
case Brightness.light:
cancelColor = Colors.black54;
break;
@ -404,7 +404,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
break;
}
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final ColorScheme colorScheme = themeData.colorScheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
@ -453,7 +453,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
}
TextStyle _titleStyle(int index) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;
assert(widget.steps[index].state != null);
@ -474,7 +474,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
}
TextStyle _subtitleStyle(int index) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TextTheme textTheme = themeData.textTheme;
assert(widget.steps[index].state != null);

View File

@ -306,7 +306,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
Widget buildMaterialSwitch(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final bool isDark = theme.brightness == Brightness.dark;
final Color activeThumbColor = widget.activeColor ?? theme.toggleableActiveColor;
@ -371,7 +371,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
}
Widget buildCupertinoSwitch(BuildContext context) {
final Size size = getSwitchSize(Theme.of(context)!);
final Size size = getSwitchSize(Theme.of(context));
return Focus(
focusNode: widget.focusNode,
autofocus: widget.autofocus,
@ -397,7 +397,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
return buildMaterialSwitch(context);
case _SwitchType.adaptive: {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.android:

View File

@ -499,7 +499,7 @@ class SwitchListTile extends StatelessWidget {
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context)!.accentColor,
selectedColor: activeColor ?? Theme.of(context).accentColor,
child: ListTile(
leading: leading,
title: title,

View File

@ -81,7 +81,7 @@ class TabBarTheme with Diagnosticable {
/// The data from the closest [TabBarTheme] instance given the build context.
static TabBarTheme of(BuildContext context) {
return Theme.of(context)!.tabBarTheme;
return Theme.of(context).tabBarTheme;
}
/// Linearly interpolate between two tab bar themes.

View File

@ -163,7 +163,7 @@ class _TabStyle extends AnimatedWidget {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TabBarTheme tabBarTheme = TabBarTheme.of(context);
final Animation<double> animation = listenable as Animation<double>;
@ -803,7 +803,7 @@ class _TabBarState extends State<TabBar> {
if (tabBarTheme.indicator != null)
return tabBarTheme.indicator!;
Color color = widget.indicatorColor ?? Theme.of(context)!.indicatorColor;
Color color = widget.indicatorColor ?? Theme.of(context).indicatorColor;
// ThemeData tries to avoid this by having indicatorColor avoid being the
// primaryColor. However, it's possible that the tab bar is on a
// Material that isn't the primaryColor. In that case, if the indicator
@ -1489,7 +1489,7 @@ class TabPageSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Color fixColor = color ?? Colors.transparent;
final Color fixSelectedColor = selectedColor ?? Theme.of(context)!.accentColor;
final Color fixSelectedColor = selectedColor ?? Theme.of(context).accentColor;
final ColorTween selectedColorTween = ColorTween(begin: fixColor, end: fixSelectedColor);
final ColorTween previousColorTween = ColorTween(begin: fixSelectedColor, end: fixColor);
final TabController? tabController = controller ?? DefaultTabController.of(context);

View File

@ -235,7 +235,7 @@ class TextButton extends ButtonStyleButton {
/// * `2 < textScaleFactor` - horizontal(4)
@override
ButtonStyle defaultStyleOf(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final EdgeInsetsGeometry scaledPadding = ButtonStyleButton.scaledPadding(

View File

@ -111,7 +111,7 @@ class TextButtonTheme extends InheritedTheme {
/// ```
static TextButtonThemeData of(BuildContext context) {
final TextButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType<TextButtonTheme>();
return buttonTheme?.data ?? Theme.of(context)!.textButtonTheme;
return buttonTheme?.data ?? Theme.of(context).textButtonTheme;
}
@override

View File

@ -64,7 +64,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
@override
void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context)!.platform) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
renderEditable.selectPositionAt(
@ -90,7 +90,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
void onSingleTapUp(TapUpDetails details) {
editableText.hideToolbar();
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context)!.platform) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
switch (details.kind) {
@ -124,7 +124,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
@override
void onSingleLongTapStart(LongPressStartDetails details) {
if (delegate.selectionEnabled) {
switch (Theme.of(_state.context)!.platform) {
switch (Theme.of(_state.context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
renderEditable.selectPositionAt(
@ -982,7 +982,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
InputDecoration _getEffectiveDecoration() {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final InputDecoration effectiveDecoration = (widget.decoration ?? const InputDecoration())
.applyDefaults(themeData.inputDecorationTheme)
.copyWith(
@ -1162,7 +1162,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
});
}
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
if (cause == SelectionChangedCause.longPress) {
@ -1255,7 +1255,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
'inherit false style must supply fontSize and textBaseline',
);
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context);
final TextStyle style = theme.textTheme.subtitle1!.merge(widget.style);
final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.primaryColorBrightness;
@ -1431,7 +1431,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
return _buildMaterialTextField(context);
case _TextFieldType.adaptive: {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.iOS:

View File

@ -229,7 +229,7 @@ class TextFormField extends FormField<String> {
builder: (FormFieldState<String> field) {
final _TextFormFieldState state = field as _TextFormFieldState;
final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
.applyDefaults(Theme.of(field.context)!.inputDecorationTheme);
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
void onChangedHandler(String value) {
field.didChange(value);
if (onChanged != null) {

View File

@ -83,7 +83,7 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke
assert(isLast != null);
// TODO(hansmuller): Should be colorScheme.onSurface
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final bool isDark = theme.colorScheme.brightness == Brightness.dark;
final Color primary = isDark ? Colors.white : Colors.black87;
@ -797,7 +797,7 @@ class _MaterialTextSelectionControls extends TextSelectionControls {
/// Builder for material-style text selection handles.
@override
Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textHeight) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final Color handleColor = TextSelectionTheme.of(context).selectionHandleColor ?? theme.colorScheme.primary;
final Widget handle = SizedBox(
width: _kHandleSize,

View File

@ -152,7 +152,7 @@ class TextSelectionTheme extends InheritedTheme {
/// ```
static TextSelectionThemeData of(BuildContext context) {
final TextSelectionTheme? selectionTheme = context.dependOnInheritedWidgetOfExactType<TextSelectionTheme>();
return selectionTheme?.data ?? Theme.of(context)!.textSelectionTheme;
return selectionTheme?.data ?? Theme.of(context).textSelectionTheme;
}
@override

View File

@ -77,14 +77,6 @@ class Theme extends StatelessWidget {
/// Defaults to [new ThemeData.fallback] if there is no [Theme] in the given
/// build context.
///
/// If [shadowThemeOnly] is true and the closest [Theme] ancestor was
/// installed by the [MaterialApp] in other words if the closest [Theme]
/// ancestor does not shadow the application's theme — then this returns null.
/// This argument should be used in situations where its useful to wrap a
/// route's widgets with a [Theme], but only when the application's overall
/// theme is being shadowed by a [Theme] widget that is deeper in the tree.
/// See [isMaterialAppTheme].
///
/// Typical usage is as follows:
///
/// ```dart
@ -124,14 +116,8 @@ class Theme extends StatelessWidget {
/// );
/// }
/// ```
static ThemeData? of(BuildContext context, { bool shadowThemeOnly = false }) {
static ThemeData of(BuildContext context) {
final _InheritedTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
if (shadowThemeOnly) {
if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme)
return null;
return inheritedTheme.theme.data;
}
final MaterialLocalizations? localizations = Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike;
final ThemeData theme = inheritedTheme?.theme.data ?? _kFallbackTheme;

View File

@ -133,7 +133,7 @@ class _TimePickerHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat(
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat,
);
@ -268,7 +268,7 @@ class _HourMinuteControl extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context)!;
final ThemeData themeData = Theme.of(context);
final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context);
final bool isDark = themeData.colorScheme.brightness == Brightness.dark;
final Color textColor = timePickerTheme.hourMinuteTextColor
@ -400,7 +400,7 @@ class _StringFragment extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context);
final TextStyle hourMinuteStyle = timePickerTheme.hourMinuteTextStyle ?? theme.textTheme.headline2!;
final Color textColor = timePickerTheme.hourMinuteTextColor ?? theme.colorScheme.onSurface;
@ -488,7 +488,7 @@ class _DayPeriodControl extends StatelessWidget {
if (selectedTime.period == DayPeriod.am) {
return;
}
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
@ -506,7 +506,7 @@ class _DayPeriodControl extends StatelessWidget {
if (selectedTime.period == DayPeriod.pm) {
return;
}
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
@ -523,7 +523,7 @@ class _DayPeriodControl extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(context);
final ColorScheme colorScheme = Theme.of(context)!.colorScheme;
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context);
final bool isDark = colorScheme.brightness == Brightness.dark;
final Color textColor = timePickerTheme.dayPeriodTextColor
@ -546,7 +546,7 @@ class _DayPeriodControl extends StatelessWidget {
final Set<MaterialState> amStates = amSelected ? <MaterialState>{MaterialState.selected} : <MaterialState>{};
final bool pmSelected = !amSelected;
final Set<MaterialState> pmStates = pmSelected ? <MaterialState>{MaterialState.selected} : <MaterialState>{};
final TextStyle textStyle = timePickerTheme.dayPeriodTextStyle ?? Theme.of(context)!.textTheme.subtitle1!;
final TextStyle textStyle = timePickerTheme.dayPeriodTextStyle ?? Theme.of(context).textTheme.subtitle1!;
final TextStyle amStyle = textStyle.copyWith(
color: MaterialStateProperty.resolveAs(textColor, amStates),
);
@ -940,7 +940,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
void didChangeDependencies() {
super.didChangeDependencies();
assert(debugCheckHasMediaQuery(context));
themeData = Theme.of(context)!;
themeData = Theme.of(context);
localizations = MaterialLocalizations.of(context);
media = MediaQuery.of(context);
}
@ -1222,7 +1222,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TimePickerThemeData pickerTheme = TimePickerTheme.of(context);
final Color backgroundColor = pickerTheme.dialBackgroundColor ?? themeData.colorScheme.onBackground.withOpacity(0.12);
final Color accentColor = pickerTheme.dialHandColor ?? themeData.colorScheme.primary;
@ -1411,7 +1411,7 @@ class _TimePickerInputState extends State<_TimePickerInput> {
final MediaQueryData media = MediaQuery.of(context);
final TimeOfDayFormat timeOfDayFormat = MaterialLocalizations.of(context).timeOfDayFormat(alwaysUse24HourFormat: media.alwaysUse24HourFormat);
final bool use24HourDials = hourFormat(of: timeOfDayFormat) != HourFormat.h;
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TextStyle hourMinuteStyle = TimePickerTheme.of(context).hourMinuteTextStyle ?? theme.textTheme.headline2!;
return Padding(
@ -1641,7 +1641,7 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final TimePickerThemeData timePickerTheme = TimePickerTheme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
@ -1789,7 +1789,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
late MaterialLocalizations localizations;
void _vibrate() {
switch (Theme.of(context)!.platform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
@ -1904,7 +1904,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
Size _dialogSize(BuildContext context) {
final Orientation orientation = MediaQuery.of(context).orientation;
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
// Constrain the textScaleFactor to prevent layout issues. Since only some
// parts of the time picker scale up with textScaleFactor, we cap the factor
// to 1.1 as that provides enough space to reasonably fit all the content.
@ -1943,7 +1943,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
final MediaQueryData media = MediaQuery.of(context);
final TimeOfDayFormat timeOfDayFormat = localizations.timeOfDayFormat(alwaysUse24HourFormat: media.alwaysUse24HourFormat);
final bool use24HourDials = hourFormat(of: timeOfDayFormat) != HourFormat.h;
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ShapeBorder shape = TimePickerTheme.of(context).shape ?? _kDefaultShape;
final Orientation orientation = media.orientation;

View File

@ -380,7 +380,7 @@ class TimePickerTheme extends InheritedTheme {
/// ```
static TimePickerThemeData of(BuildContext context) {
final TimePickerTheme? timePickerTheme = context.dependOnInheritedWidgetOfExactType<TimePickerTheme>();
return timePickerTheme?.data ?? Theme.of(context)!.timePickerTheme;
return timePickerTheme?.data ?? Theme.of(context).timePickerTheme;
}
@override

View File

@ -575,7 +575,7 @@ class ToggleButtons extends StatelessWidget {
'There are ${focusNodes!.length} focus nodes, while '
'there are ${children.length} children.'
);
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context);
final TextDirection textDirection = Directionality.of(context);
@ -772,7 +772,7 @@ class _ToggleButton extends StatelessWidget {
Color? currentFocusColor;
Color? currentHoverColor;
Color? currentSplashColor;
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context);
if (onPressed != null && selected) {

View File

@ -266,7 +266,7 @@ class ToggleButtonsTheme extends InheritedTheme {
/// ```
static ToggleButtonsThemeData of(BuildContext context) {
final ToggleButtonsTheme? toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType<ToggleButtonsTheme>();
return toggleButtonsTheme?.data ?? Theme.of(context)!.toggleButtonsTheme;
return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme;
}
@override

View File

@ -266,7 +266,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
// https://material.io/components/tooltips#specs
double _getDefaultTooltipHeight() {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.macOS:
case TargetPlatform.linux:
@ -278,7 +278,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
}
EdgeInsets _getDefaultPadding() {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.macOS:
case TargetPlatform.linux:
@ -290,7 +290,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
}
double _getDefaultFontSize() {
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
switch (theme.platform) {
case TargetPlatform.macOS:
case TargetPlatform.linux:
@ -454,7 +454,7 @@ 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);
final TextStyle defaultTextStyle;
final BoxDecoration defaultDecoration;
@ -603,7 +603,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,

View File

@ -239,7 +239,7 @@ class TooltipTheme extends InheritedTheme {
/// ```
static TooltipThemeData of(BuildContext context) {
final TooltipTheme? tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>();
return tooltipTheme?.data ?? Theme.of(context)!.tooltipTheme;
return tooltipTheme?.data ?? Theme.of(context).tooltipTheme;
}
@override

View File

@ -133,7 +133,7 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
assert(debugCheckHasMaterialLocalizations(context));
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = Theme.of(context)!;
final ThemeData theme = Theme.of(context);
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
Widget accountDetails = CustomMultiChildLayout(
@ -359,7 +359,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
label: MaterialLocalizations.of(context).signedInLabel,
child: DrawerHeader(
decoration: widget.decoration ?? BoxDecoration(
color: Theme.of(context)!.primaryColor,
color: Theme.of(context).primaryColor,
),
margin: widget.margin,
padding: const EdgeInsetsDirectional.only(top: 16.0, start: 16.0),

View File

@ -15,7 +15,7 @@ void main() {
home: const Placeholder(),
builder: (BuildContext context, Widget? child) {
log.add('build');
expect(Theme.of(context)!.primaryColor, Colors.green);
expect(Theme.of(context).primaryColor, Colors.green);
expect(Directionality.of(context), TextDirection.ltr);
expect(child, isA<Navigator>());
return const Placeholder();
@ -47,7 +47,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
log.add('build');
expect(Theme.of(context)!.primaryColor, Colors.yellow);
expect(Theme.of(context).primaryColor, Colors.yellow);
expect(Directionality.of(context), TextDirection.rtl);
return const Placeholder();
},

View File

@ -531,7 +531,7 @@ void main() {
themeMode: ThemeMode.light,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -552,7 +552,7 @@ void main() {
themeMode: ThemeMode.light,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -577,7 +577,7 @@ void main() {
themeMode: ThemeMode.dark,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -598,7 +598,7 @@ void main() {
themeMode: ThemeMode.dark,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -625,7 +625,7 @@ void main() {
themeMode: ThemeMode.system,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -651,7 +651,7 @@ void main() {
themeMode: ThemeMode.system,
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -674,7 +674,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -695,7 +695,7 @@ void main() {
MaterialApp(
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -719,7 +719,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -746,7 +746,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -772,7 +772,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -805,7 +805,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
@ -832,7 +832,7 @@ void main() {
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context)!;
appliedTheme = Theme.of(context);
return const SizedBox();
},
),

View File

@ -88,7 +88,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return Theme(
data: Theme.of(context)!.copyWith(bottomAppBarColor: const Color(0xffffff00)),
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: null,
@ -113,7 +113,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return Theme(
data: Theme.of(context)!.copyWith(bottomAppBarColor: const Color(0xffffff00)),
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: null,

Some files were not shown because too many files have changed in this diff Show More