From 0490fd75aa5d59a7f2a4dae4c62543fc6e7b33cf Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 2 Nov 2020 09:20:42 -0800 Subject: [PATCH] Make Theme.of non-nullable (#68922) --- packages/flutter/lib/src/material/about.dart | 34 +++++++++---------- packages/flutter/lib/src/material/app.dart | 4 +-- .../flutter/lib/src/material/app_bar.dart | 12 +++---- .../lib/src/material/app_bar_theme.dart | 2 +- .../flutter/lib/src/material/back_button.dart | 2 +- packages/flutter/lib/src/material/banner.dart | 6 ++-- .../lib/src/material/banner_theme.dart | 2 +- .../lib/src/material/bottom_app_bar.dart | 2 +- .../src/material/bottom_app_bar_theme.dart | 2 +- .../src/material/bottom_navigation_bar.dart | 2 +- .../material/bottom_navigation_bar_theme.dart | 2 +- .../lib/src/material/bottom_sheet.dart | 6 ++-- .../lib/src/material/button_bar_theme.dart | 2 +- .../lib/src/material/button_theme.dart | 2 +- packages/flutter/lib/src/material/card.dart | 2 +- .../flutter/lib/src/material/card_theme.dart | 2 +- .../flutter/lib/src/material/checkbox.dart | 10 +++--- .../lib/src/material/checkbox_list_tile.dart | 2 +- packages/flutter/lib/src/material/chip.dart | 4 +-- .../flutter/lib/src/material/chip_theme.dart | 2 +- .../lib/src/material/circle_avatar.dart | 2 +- .../flutter/lib/src/material/data_table.dart | 8 ++--- .../lib/src/material/data_table_theme.dart | 2 +- packages/flutter/lib/src/material/dialog.dart | 6 ++-- .../lib/src/material/dialog_theme.dart | 2 +- .../flutter/lib/src/material/divider.dart | 2 +- .../lib/src/material/divider_theme.dart | 2 +- packages/flutter/lib/src/material/drawer.dart | 4 +-- .../lib/src/material/drawer_header.dart | 4 +-- .../flutter/lib/src/material/dropdown.dart | 18 +++++----- .../lib/src/material/elevated_button.dart | 2 +- .../src/material/elevated_button_theme.dart | 2 +- .../lib/src/material/elevation_overlay.dart | 4 +-- .../flutter/lib/src/material/expand_icon.dart | 2 +- .../lib/src/material/expansion_tile.dart | 2 +- .../flutter/lib/src/material/feedback.dart | 2 +- .../flutter/lib/src/material/flat_button.dart | 2 +- .../lib/src/material/flexible_space_bar.dart | 2 +- .../src/material/floating_action_button.dart | 2 +- .../lib/src/material/grid_tile_bar.dart | 2 +- .../flutter/lib/src/material/icon_button.dart | 2 +- .../flutter/lib/src/material/ink_well.dart | 12 +++---- .../lib/src/material/input_decorator.dart | 4 +-- .../flutter/lib/src/material/list_tile.dart | 2 +- .../flutter/lib/src/material/material.dart | 8 ++--- .../lib/src/material/material_button.dart | 2 +- .../lib/src/material/mergeable_material.dart | 4 +-- .../lib/src/material/navigation_rail.dart | 4 +-- .../src/material/navigation_rail_theme.dart | 2 +- .../lib/src/material/outline_button.dart | 6 ++-- .../lib/src/material/outlined_button.dart | 4 +-- .../src/material/outlined_button_theme.dart | 2 +- packages/flutter/lib/src/material/page.dart | 2 +- .../src/material/page_transitions_theme.dart | 2 +- .../src/material/paginated_data_table.dart | 2 +- .../pickers/calendar_date_picker.dart | 16 ++++----- .../pickers/calendar_date_range_picker.dart | 10 +++--- .../pickers/date_picker_deprecated.dart | 4 +-- .../material/pickers/date_picker_dialog.dart | 2 +- .../material/pickers/date_picker_header.dart | 2 +- .../pickers/date_range_picker_dialog.dart | 6 ++-- .../material/pickers/input_date_picker.dart | 2 +- .../pickers/input_date_range_picker.dart | 2 +- .../flutter/lib/src/material/popup_menu.dart | 8 ++--- .../lib/src/material/popup_menu_theme.dart | 2 +- .../lib/src/material/progress_indicator.dart | 8 ++--- packages/flutter/lib/src/material/radio.dart | 2 +- .../lib/src/material/radio_list_tile.dart | 2 +- .../lib/src/material/raised_button.dart | 2 +- .../lib/src/material/range_slider.dart | 6 ++-- .../lib/src/material/refresh_indicator.dart | 6 ++-- .../flutter/lib/src/material/scaffold.dart | 2 +- .../flutter/lib/src/material/scrollbar.dart | 2 +- packages/flutter/lib/src/material/search.dart | 2 +- .../lib/src/material/selectable_text.dart | 6 ++-- packages/flutter/lib/src/material/slider.dart | 8 ++--- .../lib/src/material/slider_theme.dart | 2 +- .../flutter/lib/src/material/snack_bar.dart | 4 +-- .../flutter/lib/src/material/stepper.dart | 12 +++---- packages/flutter/lib/src/material/switch.dart | 6 ++-- .../lib/src/material/switch_list_tile.dart | 2 +- .../lib/src/material/tab_bar_theme.dart | 2 +- packages/flutter/lib/src/material/tabs.dart | 6 ++-- .../flutter/lib/src/material/text_button.dart | 2 +- .../lib/src/material/text_button_theme.dart | 2 +- .../flutter/lib/src/material/text_field.dart | 14 ++++---- .../lib/src/material/text_form_field.dart | 2 +- .../lib/src/material/text_selection.dart | 4 +-- .../src/material/text_selection_theme.dart | 2 +- packages/flutter/lib/src/material/theme.dart | 16 +-------- .../flutter/lib/src/material/time_picker.dart | 28 +++++++-------- .../lib/src/material/time_picker_theme.dart | 2 +- .../lib/src/material/toggle_buttons.dart | 4 +-- .../src/material/toggle_buttons_theme.dart | 2 +- .../flutter/lib/src/material/tooltip.dart | 10 +++--- .../lib/src/material/tooltip_theme.dart | 2 +- .../material/user_accounts_drawer_header.dart | 4 +-- .../test/material/app_builder_test.dart | 4 +-- packages/flutter/test/material/app_test.dart | 26 +++++++------- .../test/material/bottom_app_bar_test.dart | 4 +-- .../material/bottom_navigation_bar_test.dart | 4 +-- packages/flutter/test/material/card_test.dart | 2 +- .../test/material/inherited_theme_test.dart | 4 +-- .../test/material/input_decorator_test.dart | 8 ++--- .../flutter/test/material/list_tile_test.dart | 2 +- packages/flutter/test/material/page_test.dart | 6 ++-- .../material/page_transitions_theme_test.dart | 10 +++--- .../test/material/popup_menu_test.dart | 2 +- .../flutter/test/material/scaffold_test.dart | 2 +- .../flutter/test/material/search_test.dart | 2 +- .../flutter/test/material/slider_test.dart | 4 +-- .../flutter/test/material/theme_test.dart | 17 +++++----- .../test/rendering/localized_fonts_test.dart | 6 ++-- .../test/widgets/inherited_model_test.dart | 4 +-- .../widgets/list_view_viewporting_test.dart | 2 +- .../flutter/test/widgets/navigator_test.dart | 2 +- .../route_notification_messages_test.dart | 2 +- 117 files changed, 279 insertions(+), 294 deletions(-) diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index e2617bb8164..6cc88b05128 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -384,16 +384,16 @@ class AboutDialog extends StatelessWidget { Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - 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: [ - 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: [ 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: [ @@ -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( diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index ad2dae6aeb7..5f1f42af317 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -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, ); } } diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 99f615155e8..78ac1365b92 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -498,7 +498,7 @@ class _AppBarState extends State { 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? parentRoute = ModalRoute.of(context); @@ -512,16 +512,16 @@ class _AppBarState extends State { 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 { 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 { leading: leading, middle: title, trailing: actions, - centerMiddle: widget._getEffectiveCenterTitle(theme!), + centerMiddle: widget._getEffectiveCenterTitle(theme), middleSpacing: widget.titleSpacing ?? appBarTheme.titleSpacing ?? NavigationToolbar.kMiddleSpacing, ); diff --git a/packages/flutter/lib/src/material/app_bar_theme.dart b/packages/flutter/lib/src/material/app_bar_theme.dart index cc19e6cb03a..c6d0a5c6976 100644 --- a/packages/flutter/lib/src/material/app_bar_theme.dart +++ b/packages/flutter/lib/src/material/app_bar_theme.dart @@ -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. diff --git a/packages/flutter/lib/src/material/back_button.dart b/packages/flutter/lib/src/material/back_button.dart index a1932961701..709c44fc912 100644 --- a/packages/flutter/lib/src/material/back_button.dart +++ b/packages/flutter/lib/src/material/back_button.dart @@ -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. diff --git a/packages/flutter/lib/src/material/banner.dart b/packages/flutter/lib/src/material/banner.dart index e50009a2130..f9ce75d91b8 100644 --- a/packages/flutter/lib/src/material/banner.dart +++ b/packages/flutter/lib/src/material/banner.dart @@ -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, diff --git a/packages/flutter/lib/src/material/banner_theme.dart b/packages/flutter/lib/src/material/banner_theme.dart index 519298be862..2d495a79fef 100644 --- a/packages/flutter/lib/src/material/banner_theme.dart +++ b/packages/flutter/lib/src/material/banner_theme.dart @@ -142,7 +142,7 @@ class MaterialBannerTheme extends InheritedTheme { /// ``` static MaterialBannerThemeData of(BuildContext context) { final MaterialBannerTheme? bannerTheme = context.dependOnInheritedWidgetOfExactType(); - return bannerTheme?.data ?? Theme.of(context)!.bannerTheme; + return bannerTheme?.data ?? Theme.of(context).bannerTheme; } @override diff --git a/packages/flutter/lib/src/material/bottom_app_bar.dart b/packages/flutter/lib/src/material/bottom_app_bar.dart index e9b51053701..7d7f10d0ee5 100644 --- a/packages/flutter/lib/src/material/bottom_app_bar.dart +++ b/packages/flutter/lib/src/material/bottom_app_bar.dart @@ -130,7 +130,7 @@ class _BottomAppBarState extends State { ) : 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, diff --git a/packages/flutter/lib/src/material/bottom_app_bar_theme.dart b/packages/flutter/lib/src/material/bottom_app_bar_theme.dart index 1612b41a930..907c455a3bd 100644 --- a/packages/flutter/lib/src/material/bottom_app_bar_theme.dart +++ b/packages/flutter/lib/src/material/bottom_app_bar_theme.dart @@ -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. diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 541c33a6104..c3bbbdbaf1f 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -823,7 +823,7 @@ class _BottomNavigationBarState extends State 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 = diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart b/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart index ad57fe7eef2..d165c2c9460 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart @@ -261,7 +261,7 @@ class BottomNavigationBarTheme extends InheritedWidget { /// ``` static BottomNavigationBarThemeData of(BuildContext context) { final BottomNavigationBarTheme? bottomNavTheme = context.dependOnInheritedWidgetOfExactType(); - return bottomNavTheme?.data ?? Theme.of(context)!.bottomNavigationBarTheme; + return bottomNavTheme?.data ?? Theme.of(context).bottomNavigationBarTheme; } @override diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index e8f007dd263..a32660e8e8a 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -248,7 +248,7 @@ class _BottomSheetState extends State { @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 extends State<_ModalBottomSheet> { ParametricCurve 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 extends PopupRoute { removeTop: true, child: Builder( builder: (BuildContext context) { - final BottomSheetThemeData sheetTheme = Theme.of(context)!.bottomSheetTheme; + final BottomSheetThemeData sheetTheme = Theme.of(context).bottomSheetTheme; return _ModalBottomSheet( route: this, backgroundColor: backgroundColor ?? sheetTheme.modalBackgroundColor ?? sheetTheme.backgroundColor, diff --git a/packages/flutter/lib/src/material/button_bar_theme.dart b/packages/flutter/lib/src/material/button_bar_theme.dart index cea6db81349..6497b3f5edf 100644 --- a/packages/flutter/lib/src/material/button_bar_theme.dart +++ b/packages/flutter/lib/src/material/button_bar_theme.dart @@ -252,7 +252,7 @@ class ButtonBarTheme extends InheritedWidget { /// ``` static ButtonBarThemeData of(BuildContext context) { final ButtonBarTheme? buttonBarTheme = context.dependOnInheritedWidgetOfExactType(); - return buttonBarTheme?.data ?? Theme.of(context)!.buttonBarTheme; + return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme; } @override diff --git a/packages/flutter/lib/src/material/button_theme.dart b/packages/flutter/lib/src/material/button_theme.dart index 99334ca4209..cdf6ae08f59 100644 --- a/packages/flutter/lib/src/material/button_theme.dart +++ b/packages/flutter/lib/src/material/button_theme.dart @@ -227,7 +227,7 @@ class ButtonTheme extends InheritedTheme { final ButtonTheme? inheritedButtonTheme = context.dependOnInheritedWidgetOfExactType(); 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( diff --git a/packages/flutter/lib/src/material/card.dart b/packages/flutter/lib/src/material/card.dart index 19981089b6c..5b99e2180d0 100644 --- a/packages/flutter/lib/src/material/card.dart +++ b/packages/flutter/lib/src/material/card.dart @@ -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( diff --git a/packages/flutter/lib/src/material/card_theme.dart b/packages/flutter/lib/src/material/card_theme.dart index 2553a4a8b7f..2f5b38b8eb4 100644 --- a/packages/flutter/lib/src/material/card_theme.dart +++ b/packages/flutter/lib/src/material/card_theme.dart @@ -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. diff --git a/packages/flutter/lib/src/material/checkbox.dart b/packages/flutter/lib/src/material/checkbox.dart index 1a2471d31f1..755f3899816 100644 --- a/packages/flutter/lib/src/material/checkbox.dart +++ b/packages/flutter/lib/src/material/checkbox.dart @@ -239,9 +239,9 @@ class _CheckboxState extends State 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 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( widget.mouseCursor ?? MaterialStateMouseCursor.clickable, @@ -274,9 +274,9 @@ class _CheckboxState extends State 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, diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 578fe552ed5..56f0ed32bf9 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -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, diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index b592d53b090..ea248176b84 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -1918,7 +1918,7 @@ class _RawChipState extends State with TickerProviderStateMixin(); - return inheritedTheme?.data ?? Theme.of(context)!.chipTheme; + return inheritedTheme?.data ?? Theme.of(context).chipTheme; } @override diff --git a/packages/flutter/lib/src/material/circle_avatar.dart b/packages/flutter/lib/src/material/circle_avatar.dart index 09f95e23629..97b07b6963d 100644 --- a/packages/flutter/lib/src/material/circle_avatar.dart +++ b/packages/flutter/lib/src/material/circle_avatar.dart @@ -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) { diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index d9b06fe96a0..327d68f0a10 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -698,7 +698,7 @@ class DataTable extends StatelessWidget { required MaterialStateProperty? 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? overlayColor, }) { - final ThemeData themeData = Theme.of(context)!; + final ThemeData themeData = Theme.of(context); label = Row( textDirection: numeric ? TextDirection.rtl : null, children: [ @@ -807,7 +807,7 @@ class DataTable extends StatelessWidget { required VoidCallback? onSelectChanged, required MaterialStateProperty? 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? effectiveHeadingRowColor = headingRowColor ?? theme.dataTableTheme.headingRowColor; final MaterialStateProperty? effectiveDataRowColor = dataRowColor diff --git a/packages/flutter/lib/src/material/data_table_theme.dart b/packages/flutter/lib/src/material/data_table_theme.dart index 6125326dd98..87411a8ab85 100644 --- a/packages/flutter/lib/src/material/data_table_theme.dart +++ b/packages/flutter/lib/src/material/data_table_theme.dart @@ -241,7 +241,7 @@ class DataTableTheme extends InheritedWidget { /// ``` static DataTableThemeData of(BuildContext context) { final DataTableTheme? dataTableTheme = context.dependOnInheritedWidgetOfExactType(); - return dataTableTheme?.data ?? Theme.of(context)!.dataTableTheme; + return dataTableTheme?.data ?? Theme.of(context).dataTableTheme; } @override diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 8c5c647d628..f6ddb9abf89 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -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) { diff --git a/packages/flutter/lib/src/material/dialog_theme.dart b/packages/flutter/lib/src/material/dialog_theme.dart index 76c131ea3a6..dc7c9a5254f 100644 --- a/packages/flutter/lib/src/material/dialog_theme.dart +++ b/packages/flutter/lib/src/material/dialog_theme.dart @@ -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. diff --git a/packages/flutter/lib/src/material/divider.dart b/packages/flutter/lib/src/material/divider.dart index 735769c7458..2c63e95e58b 100644 --- a/packages/flutter/lib/src/material/divider.dart +++ b/packages/flutter/lib/src/material/divider.dart @@ -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; diff --git a/packages/flutter/lib/src/material/divider_theme.dart b/packages/flutter/lib/src/material/divider_theme.dart index 24298e56d99..af71aa6b141 100644 --- a/packages/flutter/lib/src/material/divider_theme.dart +++ b/packages/flutter/lib/src/material/divider_theme.dart @@ -161,7 +161,7 @@ class DividerTheme extends InheritedTheme { /// ``` static DividerThemeData of(BuildContext context) { final DividerTheme? dividerTheme = context.dependOnInheritedWidgetOfExactType(); - return dividerTheme?.data ?? Theme.of(context)!.dividerTheme; + return dividerTheme?.data ?? Theme.of(context).dividerTheme; } @override diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index ff6de834ad4..50e276e198c 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart @@ -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 with SingleTickerPro } } else { final bool platformHasBackButton; - switch (Theme.of(context)!.platform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: platformHasBackButton = true; break; diff --git a/packages/flutter/lib/src/material/drawer_header.dart b/packages/flutter/lib/src/material/drawer_header.dart index 4d06b0b800a..441175cff61 100644 --- a/packages/flutter/lib/src/material/drawer_header.dart +++ b/packages/flutter/lib/src/material/drawer_header.dart @@ -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, diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index c3bf886f142..22f2768c6be 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -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 extends State<_DropdownMenu> { 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 extends State> 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 extends State> 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 extends State> 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 extends State> 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 extends State> 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 extends State> 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 extends FormField { final _DropdownButtonFormFieldState state = field as _DropdownButtonFormFieldState; 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. diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 2e59e07ac44..07fedef344c 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -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( diff --git a/packages/flutter/lib/src/material/elevated_button_theme.dart b/packages/flutter/lib/src/material/elevated_button_theme.dart index cc27e827298..78b4f0037b6 100644 --- a/packages/flutter/lib/src/material/elevated_button_theme.dart +++ b/packages/flutter/lib/src/material/elevated_button_theme.dart @@ -111,7 +111,7 @@ class ElevatedButtonTheme extends InheritedTheme { /// ``` static ElevatedButtonThemeData of(BuildContext context) { final ElevatedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType(); - return buttonTheme?.data ?? Theme.of(context)!.elevatedButtonTheme; + return buttonTheme?.data ?? Theme.of(context).elevatedButtonTheme; } @override diff --git a/packages/flutter/lib/src/material/elevation_overlay.dart b/packages/flutter/lib/src/material/elevation_overlay.dart index 41024ce9288..cc699c6d6f4 100644 --- a/packages/flutter/lib/src/material/elevation_overlay.dart +++ b/packages/flutter/lib/src/material/elevation_overlay.dart @@ -43,7 +43,7 @@ class ElevationOverlay { /// * , 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 diff --git a/packages/flutter/lib/src/material/expand_icon.dart b/packages/flutter/lib/src/material/expand_icon.dart index 934ff489d8e..1f9fba1426d 100644 --- a/packages/flutter/lib/src/material/expand_icon.dart +++ b/packages/flutter/lib/src/material/expand_icon.dart @@ -155,7 +155,7 @@ class _ExpandIconState extends State with SingleTickerProviderStateM return widget.color!; } - switch(Theme.of(context)!.brightness) { + switch(Theme.of(context).brightness) { case Brightness.light: return Colors.black54; case Brightness.dark: diff --git a/packages/flutter/lib/src/material/expansion_tile.dart b/packages/flutter/lib/src/material/expansion_tile.dart index da5cb9ec1b7..83b01612731 100644 --- a/packages/flutter/lib/src/material/expansion_tile.dart +++ b/packages/flutter/lib/src/material/expansion_tile.dart @@ -253,7 +253,7 @@ class _ExpansionTileState extends State 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 diff --git a/packages/flutter/lib/src/material/feedback.dart b/packages/flutter/lib/src/material/feedback.dart index 784c491d603..dab6197f4cc 100644 --- a/packages/flutter/lib/src/material/feedback.dart +++ b/packages/flutter/lib/src/material/feedback.dart @@ -167,5 +167,5 @@ class Feedback { }; } - static TargetPlatform _platform(BuildContext context) => Theme.of(context)!.platform; + static TargetPlatform _platform(BuildContext context) => Theme.of(context).platform; } diff --git a/packages/flutter/lib/src/material/flat_button.dart b/packages/flutter/lib/src/material/flat_button.dart index 518238a3b30..03acbe56258 100644 --- a/packages/flutter/lib/src/material/flat_button.dart +++ b/packages/flutter/lib/src/material/flat_button.dart @@ -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, diff --git a/packages/flutter/lib/src/material/flexible_space_bar.dart b/packages/flutter/lib/src/material/flexible_space_bar.dart index 63825161e20..da9f3975734 100644 --- a/packages/flutter/lib/src/material/flexible_space_bar.dart +++ b/packages/flutter/lib/src/material/flexible_space_bar.dart @@ -339,7 +339,7 @@ class _FlexibleSpaceBarState extends State { // title if (widget.title != null) { - final ThemeData theme = Theme.of(context)!; + final ThemeData theme = Theme.of(context); Widget? title; switch (theme.platform) { diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index b70addb9988..5ba544233ac 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -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 diff --git a/packages/flutter/lib/src/material/grid_tile_bar.dart b/packages/flutter/lib/src/material/grid_tile_bar.dart index 0547af0f0ef..d75a432da9d 100644 --- a/packages/flutter/lib/src/material/grid_tile_bar.dart +++ b/packages/flutter/lib/src/material/grid_tile_bar.dart @@ -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, diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 86293f0e0c9..580506b4340 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -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; diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart index e00de3191e4..1b2647a1741 100644 --- a/packages/flutter/lib/src/material/ink_well.dart +++ b/packages/flutter/lib/src/material/ink_well.dart @@ -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 pressed = {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 pressed = {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( widget.mouseCursor ?? MaterialStateMouseCursor.clickable, diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 291b828dbd7..391f96e6bdb 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1956,7 +1956,7 @@ class _InputDecoratorState extends State 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 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!; diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 23cb92bc95e..c007df825ea 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -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; diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index e5bdb5aeca8..ee8ce667c31 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -338,7 +338,7 @@ class _MaterialState extends State 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 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 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 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, ); } diff --git a/packages/flutter/lib/src/material/material_button.dart b/packages/flutter/lib/src/material/material_button.dart index 9e055cf3f18..5b8609567ed 100644 --- a/packages/flutter/lib/src/material/material_button.dart +++ b/packages/flutter/lib/src/material/material_button.dart @@ -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( diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index a548d4e9b10..5a033b74e3a 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -536,7 +536,7 @@ class _MergeableMaterialState extends State 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 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, ), diff --git a/packages/flutter/lib/src/material/navigation_rail.dart b/packages/flutter/lib/src/material/navigation_rail.dart index be2a01f92b3..f1440775e36 100644 --- a/packages/flutter/lib/src/material/navigation_rail.dart +++ b/packages/flutter/lib/src/material/navigation_rail.dart @@ -431,7 +431,7 @@ class _NavigationRailState extends State 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, diff --git a/packages/flutter/lib/src/material/navigation_rail_theme.dart b/packages/flutter/lib/src/material/navigation_rail_theme.dart index 8c6f51aa5de..f0cbbd819c4 100644 --- a/packages/flutter/lib/src/material/navigation_rail_theme.dart +++ b/packages/flutter/lib/src/material/navigation_rail_theme.dart @@ -202,7 +202,7 @@ class NavigationRailTheme extends InheritedTheme { /// ``` static NavigationRailThemeData of(BuildContext context) { final NavigationRailTheme? navigationRailTheme = context.dependOnInheritedWidgetOfExactType(); - return navigationRailTheme?.data ?? Theme.of(context)!.navigationRailTheme; + return navigationRailTheme?.data ?? Theme.of(context).navigationRailTheme; } @override diff --git a/packages/flutter/lib/src/material/outline_button.dart b/packages/flutter/lib/src/material/outline_button.dart index 34e3c663b8a..8c920b9b89e 100644 --- a/packages/flutter/lib/src/material/outline_button.dart +++ b/packages/flutter/lib/src/material/outline_button.dart @@ -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 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, diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index 7ddc29fb91f..552e9569d54 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -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))), diff --git a/packages/flutter/lib/src/material/outlined_button_theme.dart b/packages/flutter/lib/src/material/outlined_button_theme.dart index 46b3bcd2bdb..688af02db39 100644 --- a/packages/flutter/lib/src/material/outlined_button_theme.dart +++ b/packages/flutter/lib/src/material/outlined_button_theme.dart @@ -111,7 +111,7 @@ class OutlinedButtonTheme extends InheritedTheme { /// ``` static OutlinedButtonThemeData of(BuildContext context) { final OutlinedButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType(); - return buttonTheme?.data ?? Theme.of(context)!.outlinedButtonTheme; + return buttonTheme?.data ?? Theme.of(context).outlinedButtonTheme; } @override diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index 0977f4a14af..98a8dc8cd2c 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -123,7 +123,7 @@ mixin MaterialRouteTransitionMixin on PageRoute { @override Widget buildTransitions(BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { - final PageTransitionsTheme theme = Theme.of(context)!.pageTransitionsTheme; + final PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme; return theme.buildTransitions(this, context, animation, secondaryAnimation, child); } } diff --git a/packages/flutter/lib/src/material/page_transitions_theme.dart b/packages/flutter/lib/src/material/page_transitions_theme.dart index 6f9482f7804..b6480af8e55 100644 --- a/packages/flutter/lib/src/material/page_transitions_theme.dart +++ b/packages/flutter/lib/src/material/page_transitions_theme.dart @@ -589,7 +589,7 @@ class PageTransitionsTheme with Diagnosticable { Animation secondaryAnimation, Widget child, ) { - TargetPlatform platform = Theme.of(context)!.platform; + TargetPlatform platform = Theme.of(context).platform; if (CupertinoRouteTransitionMixin.isPopGestureInProgress(route)) platform = TargetPlatform.iOS; diff --git a/packages/flutter/lib/src/material/paginated_data_table.dart b/packages/flutter/lib/src/material/paginated_data_table.dart index 1402eeb729f..03228f5b15e 100644 --- a/packages/flutter/lib/src/material/paginated_data_table.dart +++ b/packages/flutter/lib/src/material/paginated_data_table.dart @@ -332,7 +332,7 @@ class PaginatedDataTableState extends State { 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 headerWidgets = []; diff --git a/packages/flutter/lib/src/material/pickers/calendar_date_picker.dart b/packages/flutter/lib/src/material/pickers/calendar_date_picker.dart index 2db426c3a1f..a8f52f50b49 100644 --- a/packages/flutter/lib/src/material/pickers/calendar_date_picker.dart +++ b/packages/flutter/lib/src/material/pickers/calendar_date_picker.dart @@ -196,7 +196,7 @@ class _CalendarDatePickerState extends State { } 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; diff --git a/packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart b/packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart index d51dd5a5723..874472b2a32 100644 --- a/packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart +++ b/packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart @@ -135,7 +135,7 @@ class _CalendarDateRangePickerState extends State { 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; diff --git a/packages/flutter/lib/src/material/pickers/date_picker_deprecated.dart b/packages/flutter/lib/src/material/pickers/date_picker_deprecated.dart index e75f169bd96..dc349e3820e 100644 --- a/packages/flutter/lib/src/material/pickers/date_picker_deprecated.dart +++ b/packages/flutter/lib/src/material/pickers/date_picker_deprecated.dart @@ -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 { @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, diff --git a/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart b/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart index 0564ac2ffd0..dcb75e5e9a9 100644 --- a/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart +++ b/packages/flutter/lib/src/material/pickers/date_picker_dialog.dart @@ -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; diff --git a/packages/flutter/lib/src/material/pickers/date_picker_header.dart b/packages/flutter/lib/src/material/pickers/date_picker_header.dart index 6e67757757d..b932064578b 100644 --- a/packages/flutter/lib/src/material/pickers/date_picker_header.dart +++ b/packages/flutter/lib/src/material/pickers/date_picker_header.dart @@ -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; diff --git a/packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart b/packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart index 09b765ad6fa..d2d8b0d3f2e 100644 --- a/packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart +++ b/packages/flutter/lib/src/material/pickers/date_range_picker_dialog.dart @@ -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; diff --git a/packages/flutter/lib/src/material/pickers/input_date_picker.dart b/packages/flutter/lib/src/material/pickers/input_date_picker.dart index 8af8db6b92c..b0f48098780 100644 --- a/packages/flutter/lib/src/material/pickers/input_date_picker.dart +++ b/packages/flutter/lib/src/material/pickers/input_date_picker.dart @@ -220,7 +220,7 @@ class _InputDatePickerFormFieldState extends State { @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(), diff --git a/packages/flutter/lib/src/material/pickers/input_date_range_picker.dart b/packages/flutter/lib/src/material/pickers/input_date_range_picker.dart index 4331e70fa5d..81dc2bd7751 100644 --- a/packages/flutter/lib/src/material/pickers/input_date_range_picker.dart +++ b/packages/flutter/lib/src/material/pickers/input_date_range_picker.dart @@ -226,7 +226,7 @@ class InputDateRangePickerState extends State { @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: [ diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 111d8ce7c49..ed95ed55d4b 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -306,7 +306,7 @@ class PopupMenuItemState> extends State { @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 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 showMenu({ 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 extends State> { ); 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, diff --git a/packages/flutter/lib/src/material/popup_menu_theme.dart b/packages/flutter/lib/src/material/popup_menu_theme.dart index 8df038ffba2..8b0fea34dde 100644 --- a/packages/flutter/lib/src/material/popup_menu_theme.dart +++ b/packages/flutter/lib/src/material/popup_menu_theme.dart @@ -147,7 +147,7 @@ class PopupMenuTheme extends InheritedTheme { /// ``` static PopupMenuThemeData of(BuildContext context) { final PopupMenuTheme? popupMenuTheme = context.dependOnInheritedWidgetOfExactType(); - return popupMenuTheme?.data ?? Theme.of(context)!.popupMenuTheme; + return popupMenuTheme?.data ?? Theme.of(context).popupMenuTheme; } @override diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index a33b312a940..1e2531f7b18 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -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 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), diff --git a/packages/flutter/lib/src/material/radio.dart b/packages/flutter/lib/src/material/radio.dart index 7dcea5f0b3a..85197bd19c7 100644 --- a/packages/flutter/lib/src/material/radio.dart +++ b/packages/flutter/lib/src/material/radio.dart @@ -335,7 +335,7 @@ class _RadioState extends State> 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: diff --git a/packages/flutter/lib/src/material/radio_list_tile.dart b/packages/flutter/lib/src/material/radio_list_tile.dart index 1ca6f5e3951..40300e6e63d 100644 --- a/packages/flutter/lib/src/material/radio_list_tile.dart +++ b/packages/flutter/lib/src/material/radio_list_tile.dart @@ -520,7 +520,7 @@ class RadioListTile 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, diff --git a/packages/flutter/lib/src/material/raised_button.dart b/packages/flutter/lib/src/material/raised_button.dart index 388958dbf97..dad6fccffaf 100644 --- a/packages/flutter/lib/src/material/raised_button.dart +++ b/packages/flutter/lib/src/material/raised_button.dart @@ -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, diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index c18b83e922c..09077d8570f 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -575,7 +575,7 @@ class _RangeSliderState extends State 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; } } diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 71ee331b864..487b53c517f 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -196,11 +196,11 @@ class RefreshIndicatorState extends State 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) )), diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 8d6cafad5ed..018c7f7e1b6 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -2907,7 +2907,7 @@ class ScaffoldState extends State 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 diff --git a/packages/flutter/lib/src/material/scrollbar.dart b/packages/flutter/lib/src/material/scrollbar.dart index ca6bdf1f5f9..af8fad608de 100644 --- a/packages/flutter/lib/src/material/scrollbar.dart +++ b/packages/flutter/lib/src/material/scrollbar.dart @@ -106,7 +106,7 @@ class _ScrollbarState extends State 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: diff --git a/packages/flutter/lib/src/material/search.dart b/packages/flutter/lib/src/material/search.dart index 7f6e26235e7..6bd632a7f55 100644 --- a/packages/flutter/lib/src/material/search.dart +++ b/packages/flutter/lib/src/material/search.dart @@ -196,7 +196,7 @@ abstract class SearchDelegate { /// * [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 diff --git a/packages/flutter/lib/src/material/selectable_text.dart b/packages/flutter/lib/src/material/selectable_text.dart index 40cad5629a7..7fc8433e333 100644 --- a/packages/flutter/lib/src/material/selectable_text.dart +++ b/packages/flutter/lib/src/material/selectable_text.dart @@ -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 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 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; diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart index a13710dfbf2..b8f611caf83 100644 --- a/packages/flutter/lib/src/material/slider.dart +++ b/packages/flutter/lib/src/material/slider.dart @@ -620,7 +620,7 @@ class _SliderState extends State 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 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 diff --git a/packages/flutter/lib/src/material/slider_theme.dart b/packages/flutter/lib/src/material/slider_theme.dart index af3ef94ca8e..faa7f382d53 100644 --- a/packages/flutter/lib/src/material/slider_theme.dart +++ b/packages/flutter/lib/src/material/slider_theme.dart @@ -112,7 +112,7 @@ class SliderTheme extends InheritedTheme { /// theme. static SliderThemeData of(BuildContext context) { final SliderTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType(); - return inheritedTheme != null ? inheritedTheme.data : Theme.of(context)!.sliderTheme; + return inheritedTheme != null ? inheritedTheme.data : Theme.of(context).sliderTheme; } @override diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 63c403ac841..892c1586eef 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -129,7 +129,7 @@ class _SnackBarActionState extends State { @override Widget build(BuildContext context) { Color? resolveForegroundColor(Set 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 { 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; diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 1057196ae4b..408f5e6f39e 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -281,7 +281,7 @@ class _StepperState extends State 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 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 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 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 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 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); diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart index 06a76326b8d..4a8014f68ad 100644 --- a/packages/flutter/lib/src/material/switch.dart +++ b/packages/flutter/lib/src/material/switch.dart @@ -306,7 +306,7 @@ class _SwitchState extends State 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 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 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: diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 8764637ec16..4a5a525ab29 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -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, diff --git a/packages/flutter/lib/src/material/tab_bar_theme.dart b/packages/flutter/lib/src/material/tab_bar_theme.dart index aa549b8d4c4..4b1c0456668 100644 --- a/packages/flutter/lib/src/material/tab_bar_theme.dart +++ b/packages/flutter/lib/src/material/tab_bar_theme.dart @@ -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. diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 4937a536882..22a36013d50 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -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 animation = listenable as Animation; @@ -803,7 +803,7 @@ class _TabBarState extends State { 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); diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index 933dd67c475..7f2911a6e46 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -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( diff --git a/packages/flutter/lib/src/material/text_button_theme.dart b/packages/flutter/lib/src/material/text_button_theme.dart index 49893a8d00c..98368f58b58 100644 --- a/packages/flutter/lib/src/material/text_button_theme.dart +++ b/packages/flutter/lib/src/material/text_button_theme.dart @@ -111,7 +111,7 @@ class TextButtonTheme extends InheritedTheme { /// ``` static TextButtonThemeData of(BuildContext context) { final TextButtonTheme? buttonTheme = context.dependOnInheritedWidgetOfExactType(); - return buttonTheme?.data ?? Theme.of(context)!.textButtonTheme; + return buttonTheme?.data ?? Theme.of(context).textButtonTheme; } @override diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index dcd73258319..533cd7602fa 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -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 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 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 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 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: diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index f5b9fdce7ba..deb9a4e1f2d 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -229,7 +229,7 @@ class TextFormField extends FormField { builder: (FormFieldState 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) { diff --git a/packages/flutter/lib/src/material/text_selection.dart b/packages/flutter/lib/src/material/text_selection.dart index f37740f8495..a7389b7dea0 100644 --- a/packages/flutter/lib/src/material/text_selection.dart +++ b/packages/flutter/lib/src/material/text_selection.dart @@ -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, diff --git a/packages/flutter/lib/src/material/text_selection_theme.dart b/packages/flutter/lib/src/material/text_selection_theme.dart index 0361a2fed44..91ca20d62b9 100644 --- a/packages/flutter/lib/src/material/text_selection_theme.dart +++ b/packages/flutter/lib/src/material/text_selection_theme.dart @@ -152,7 +152,7 @@ class TextSelectionTheme extends InheritedTheme { /// ``` static TextSelectionThemeData of(BuildContext context) { final TextSelectionTheme? selectionTheme = context.dependOnInheritedWidgetOfExactType(); - return selectionTheme?.data ?? Theme.of(context)!.textSelectionTheme; + return selectionTheme?.data ?? Theme.of(context).textSelectionTheme; } @override diff --git a/packages/flutter/lib/src/material/theme.dart b/packages/flutter/lib/src/material/theme.dart index c5a918af961..9fe24c7b0cf 100644 --- a/packages/flutter/lib/src/material/theme.dart +++ b/packages/flutter/lib/src/material/theme.dart @@ -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(context, MaterialLocalizations); final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike; final ThemeData theme = inheritedTheme?.theme.data ?? _kFallbackTheme; diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index abbe3568309..8e040c33052 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -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 amStates = amSelected ? {MaterialState.selected} : {}; final bool pmSelected = !amSelected; final Set pmStates = pmSelected ? {MaterialState.selected} : {}; - 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; diff --git a/packages/flutter/lib/src/material/time_picker_theme.dart b/packages/flutter/lib/src/material/time_picker_theme.dart index c8bd19741ea..dd5352003e8 100644 --- a/packages/flutter/lib/src/material/time_picker_theme.dart +++ b/packages/flutter/lib/src/material/time_picker_theme.dart @@ -380,7 +380,7 @@ class TimePickerTheme extends InheritedTheme { /// ``` static TimePickerThemeData of(BuildContext context) { final TimePickerTheme? timePickerTheme = context.dependOnInheritedWidgetOfExactType(); - return timePickerTheme?.data ?? Theme.of(context)!.timePickerTheme; + return timePickerTheme?.data ?? Theme.of(context).timePickerTheme; } @override diff --git a/packages/flutter/lib/src/material/toggle_buttons.dart b/packages/flutter/lib/src/material/toggle_buttons.dart index d21d631fd9b..63763803867 100644 --- a/packages/flutter/lib/src/material/toggle_buttons.dart +++ b/packages/flutter/lib/src/material/toggle_buttons.dart @@ -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) { diff --git a/packages/flutter/lib/src/material/toggle_buttons_theme.dart b/packages/flutter/lib/src/material/toggle_buttons_theme.dart index bd51807e87c..9d67447ba2e 100644 --- a/packages/flutter/lib/src/material/toggle_buttons_theme.dart +++ b/packages/flutter/lib/src/material/toggle_buttons_theme.dart @@ -266,7 +266,7 @@ class ToggleButtonsTheme extends InheritedTheme { /// ``` static ToggleButtonsThemeData of(BuildContext context) { final ToggleButtonsTheme? toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType(); - return toggleButtonsTheme?.data ?? Theme.of(context)!.toggleButtonsTheme; + return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme; } @override diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index 65656618979..3cee787b465 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -266,7 +266,7 @@ class _TooltipState extends State 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 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 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 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, diff --git a/packages/flutter/lib/src/material/tooltip_theme.dart b/packages/flutter/lib/src/material/tooltip_theme.dart index f50b9d704cd..c65c8f19d2e 100644 --- a/packages/flutter/lib/src/material/tooltip_theme.dart +++ b/packages/flutter/lib/src/material/tooltip_theme.dart @@ -239,7 +239,7 @@ class TooltipTheme extends InheritedTheme { /// ``` static TooltipThemeData of(BuildContext context) { final TooltipTheme? tooltipTheme = context.dependOnInheritedWidgetOfExactType(); - return tooltipTheme?.data ?? Theme.of(context)!.tooltipTheme; + return tooltipTheme?.data ?? Theme.of(context).tooltipTheme; } @override diff --git a/packages/flutter/lib/src/material/user_accounts_drawer_header.dart b/packages/flutter/lib/src/material/user_accounts_drawer_header.dart index 7b932a0adea..84f7aca4e58 100644 --- a/packages/flutter/lib/src/material/user_accounts_drawer_header.dart +++ b/packages/flutter/lib/src/material/user_accounts_drawer_header.dart @@ -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 { 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), diff --git a/packages/flutter/test/material/app_builder_test.dart b/packages/flutter/test/material/app_builder_test.dart index 84f7f4a6b4b..262017178b5 100644 --- a/packages/flutter/test/material/app_builder_test.dart +++ b/packages/flutter/test/material/app_builder_test.dart @@ -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()); 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(); }, diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index 8b9c15e4bd4..7d2d6284c4a 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -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(); }, ), diff --git a/packages/flutter/test/material/bottom_app_bar_test.dart b/packages/flutter/test/material/bottom_app_bar_test.dart index 0d2cc6e22c7..8fcb1abe9e1 100644 --- a/packages/flutter/test/material/bottom_app_bar_test.dart +++ b/packages/flutter/test/material/bottom_app_bar_test.dart @@ -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, diff --git a/packages/flutter/test/material/bottom_navigation_bar_test.dart b/packages/flutter/test/material/bottom_navigation_bar_test.dart index 5fa74b7c585..ebce09a4544 100644 --- a/packages/flutter/test/material/bottom_navigation_bar_test.dart +++ b/packages/flutter/test/material/bottom_navigation_bar_test.dart @@ -873,7 +873,7 @@ void main() { await tester.tap(find.text('Alarm')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('Alarm')))!.brightness, equals(Brightness.dark)); + expect(Theme.of(tester.element(find.text('Alarm'))).brightness, equals(Brightness.dark)); }); testWidgets('BottomNavigationBar inherits shadowed app theme for fixed navbar', (WidgetTester tester) async { @@ -911,7 +911,7 @@ void main() { await tester.tap(find.text('Alarm')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('Alarm')))!.brightness, equals(Brightness.dark)); + expect(Theme.of(tester.element(find.text('Alarm'))).brightness, equals(Brightness.dark)); }); testWidgets('BottomNavigationBar iconSize test', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/card_test.dart b/packages/flutter/test/material/card_test.dart index 50436aaa9a4..99c029a2b85 100644 --- a/packages/flutter/test/material/card_test.dart +++ b/packages/flutter/test/material/card_test.dart @@ -176,7 +176,7 @@ void main() { testWidgets('Card clipBehavior property defers to theme when null', (WidgetTester tester) async { await tester.pumpWidget(Builder(builder: (BuildContext context) { - final ThemeData themeData = Theme.of(context)!; + final ThemeData themeData = Theme.of(context); return Theme( data: themeData.copyWith( cardTheme: themeData.cardTheme.copyWith( diff --git a/packages/flutter/test/material/inherited_theme_test.dart b/packages/flutter/test/material/inherited_theme_test.dart index 7c9190ec3b5..03df6a534f9 100644 --- a/packages/flutter/test/material/inherited_theme_test.dart +++ b/packages/flutter/test/material/inherited_theme_test.dart @@ -17,7 +17,7 @@ void main() { builder: (BuildContext context) { return Container( key: primaryContainerKey, - color: Theme.of(context)!.primaryColor, + color: Theme.of(context).primaryColor, ); }, ); @@ -31,7 +31,7 @@ void main() { builder: (BuildContext context) { navigatorContext = context; return Theme( - data: Theme.of(context)!.copyWith(primaryColor: primaryColor), + data: Theme.of(context).copyWith(primaryColor: primaryColor), child: Builder( // Introduce a context so the shadow Theme is visible to captureAll(). builder: (BuildContext context) { return Center( diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index fe960dca762..d628b2feb22 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -32,7 +32,7 @@ Widget buildInputDecorator({ child: Builder( builder: (BuildContext context) { return Theme( - data: Theme.of(context)!.copyWith( + data: Theme.of(context).copyWith( inputDecorationTheme: inputDecorationTheme, visualDensity: visualDensity, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, @@ -4204,7 +4204,7 @@ void main() { child: Builder( builder: (BuildContext context) { return Theme( - data: Theme.of(context)!, + data: Theme.of(context), child: Align( alignment: Alignment.topLeft, child: TextField( @@ -4316,7 +4316,7 @@ void main() { child: Builder( builder: (BuildContext context) { return Theme( - data: Theme.of(context)!.copyWith(visualDensity: visualDensity), + data: Theme.of(context).copyWith(visualDensity: visualDensity), child: Center( child: Row( children: [ @@ -4389,7 +4389,7 @@ void main() { child: Builder( builder: (BuildContext context) { return Theme( - data: Theme.of(context)!.copyWith(visualDensity: VisualDensity.compact), + data: Theme.of(context).copyWith(visualDensity: VisualDensity.compact), child: Center( child: Row( children: [ diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index a8fbcfffa2c..c03b297e9f7 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -279,7 +279,7 @@ void main() { textColor: textColor, child: Builder( builder: (BuildContext context) { - theme = Theme.of(context)!; + theme = Theme.of(context); return ListTile( enabled: enabled, selected: selected, diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 504e24dd082..588abf8c571 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -309,7 +309,7 @@ void main() { final Offset helloPosition2 = tester.getCenter(find.text('HELLO')); expect(helloPosition1.dx, lessThan(helloPosition2.dx)); expect(helloPosition1.dy, helloPosition2.dy); - expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.iOS); + expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.iOS); await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: TargetPlatform.android), @@ -325,7 +325,7 @@ void main() { // frame in which the theme animation ends. // 3. End all the other animations. expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2); - expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.android); + expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.android); final Offset helloPosition3 = tester.getCenter(find.text('HELLO')); expect(helloPosition3, helloPosition2); expect(find.text('PUSH'), findsOneWidget); @@ -365,7 +365,7 @@ void main() { final Offset helloPosition6 = tester.getCenter(find.text('HELLO')); expect(helloPosition5.dx, lessThan(helloPosition6.dx)); expect(helloPosition5.dy, helloPosition6.dy); - expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.macOS); + expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.macOS); }); testWidgets('test no back gesture on fullscreen dialogs', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/page_transitions_theme_test.dart b/packages/flutter/test/material/page_transitions_theme_test.dart index 6649d98c772..f31c98dfba8 100644 --- a/packages/flutter/test/material/page_transitions_theme_test.dart +++ b/packages/flutter/test/material/page_transitions_theme_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('Default PageTransitionsTheme platform', (WidgetTester tester) async { await tester.pumpWidget(const MaterialApp(home: Text('home'))); - final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home')))!.pageTransitionsTheme; + final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home'))).pageTransitionsTheme; expect(theme.builders, isNotNull); for (final TargetPlatform platform in TargetPlatform.values) { if (platform == TargetPlatform.fuchsia) { @@ -38,7 +38,7 @@ void main() { ), ); - expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); expect(find.byType(CupertinoPageTransition), findsOneWidget); await tester.tap(find.text('push')); @@ -71,7 +71,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); expect(findFadeUpwardsPageTransition(), findsOneWidget); await tester.tap(find.text('push')); @@ -111,7 +111,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); expect(findOpenUpwardsPageTransition(), findsOneWidget); await tester.tap(find.text('push')); @@ -151,7 +151,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); expect(findZoomPageTransition(), findsOneWidget); await tester.tap(find.text('push')); diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index ec7bc25bb75..1ea4fe8e621 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -1270,7 +1270,7 @@ void main() { textDirection: textDirection, child: PopupMenuTheme( data: PopupMenuTheme.of(context).copyWith( - textStyle: Theme.of(context)!.textTheme.subtitle1!.copyWith(fontSize: fontSize), + textStyle: Theme.of(context).textTheme.subtitle1!.copyWith(fontSize: fontSize), ), child: child!, ), diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 01d8a4caf62..3abdd6f87ea 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -1811,7 +1811,7 @@ void main() { late FlutterError error; try { key.currentState!.showBottomSheet((BuildContext context) { - final ThemeData themeData = Theme.of(context)!; + final ThemeData themeData = Theme.of(context); return Container( decoration: BoxDecoration( border: Border(top: BorderSide(color: themeData.disabledColor)) diff --git a/packages/flutter/test/material/search_test.dart b/packages/flutter/test/material/search_test.dart index eff15bafd1e..94328acafe3 100644 --- a/packages/flutter/test/material/search_test.dart +++ b/packages/flutter/test/material/search_test.dart @@ -819,7 +819,7 @@ class _TestSearchDelegate extends SearchDelegate { if (defaultAppBarTheme) { return super.appBarTheme(context); } - final ThemeData theme = Theme.of(context)!; + final ThemeData theme = Theme.of(context); return theme.copyWith( inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)), ); diff --git a/packages/flutter/test/material/slider_test.dart b/packages/flutter/test/material/slider_test.dart index e75421694d5..6fad7c4a54b 100644 --- a/packages/flutter/test/material/slider_test.dart +++ b/packages/flutter/test/material/slider_test.dart @@ -991,8 +991,8 @@ void main() { data: MediaQueryData(textScaleFactor: textScaleFactor), child: Material( child: Theme( - data: Theme.of(context)!.copyWith( - sliderTheme: Theme.of(context)!.sliderTheme.copyWith(showValueIndicator: show), + data: Theme.of(context).copyWith( + sliderTheme: Theme.of(context).sliderTheme.copyWith(showValueIndicator: show), ), child: Center( child: OverflowBox( diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index 2d948dcb4fa..e13f177b56e 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/theme_test.dart @@ -44,7 +44,7 @@ void main() { await tester.tap(find.byKey(popupMenuButtonKey)); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('menuItem')))!.brightness, equals(Brightness.dark)); + expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.dark)); }); testWidgets('Fallback theme', (WidgetTester tester) async { @@ -59,7 +59,6 @@ void main() { ); expect(Theme.of(capturedContext), equals(ThemeData.localize(ThemeData.fallback(), defaultGeometryTheme))); - expect(Theme.of(capturedContext, shadowThemeOnly: true), isNull); }); testWidgets('ThemeData.localize memoizes the result', (WidgetTester tester) async { @@ -114,7 +113,7 @@ void main() { await tester.tap(find.byKey(popupMenuButtonKey)); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('menuItem')))!.brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.light)); }); testWidgets('DropdownMenu inherits shadowed app theme', (WidgetTester tester) async { @@ -149,7 +148,7 @@ void main() { await tester.pump(const Duration(seconds: 1)); for (final Element item in tester.elementList(find.text('menuItem'))) - expect(Theme.of(item)!.brightness, equals(Brightness.light)); + expect(Theme.of(item).brightness, equals(Brightness.light)); }); testWidgets('ModalBottomSheet inherits shadowed app theme', (WidgetTester tester) async { @@ -181,7 +180,7 @@ void main() { await tester.tap(find.text('SHOW')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('bottomSheet')))!.brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('bottomSheet'))).brightness, equals(Brightness.light)); await tester.tap(find.text('bottomSheet')); // dismiss the bottom sheet await tester.pump(const Duration(seconds: 1)); @@ -218,7 +217,7 @@ void main() { await tester.tap(find.text('SHOW')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('dialog')))!.brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('dialog'))).brightness, equals(Brightness.light)); }); testWidgets("Scaffold inherits theme's scaffoldBackgroundColor", (WidgetTester tester) async { @@ -349,7 +348,7 @@ void main() { child: Theme( data: customTheme, child: Builder(builder: (BuildContext context) { - final ThemeData theme = Theme.of(context)!; + final ThemeData theme = Theme.of(context); actualFontSize = theme.primaryTextTheme.bodyText2!.fontSize!; return Text( 'A', @@ -368,7 +367,7 @@ void main() { textDirection: TextDirection.ltr, child: Builder( builder: (BuildContext context) { - theme = Theme.of(context)!; + theme = Theme.of(context); return const Text('A'); }, ), @@ -686,7 +685,7 @@ class _TestState extends State { testBuildCalled += 1; return Container( decoration: BoxDecoration( - color: Theme.of(context)!.primaryColor, + color: Theme.of(context).primaryColor, ), ); } diff --git a/packages/flutter/test/rendering/localized_fonts_test.dart b/packages/flutter/test/rendering/localized_fonts_test.dart index 43b2e519d0a..2bb460fd6fc 100644 --- a/packages/flutter/test/rendering/localized_fonts_test.dart +++ b/packages/flutter/test/rendering/localized_fonts_test.dart @@ -23,7 +23,7 @@ void main() { home: Builder( builder: (BuildContext context) { const String character = '骨'; - final TextStyle style = Theme.of(context)!.textTheme.headline2!; + final TextStyle style = Theme.of(context).textTheme.headline2!; return Scaffold( body: Container( padding: const EdgeInsets.all(48.0), @@ -67,7 +67,7 @@ void main() { home: Builder( builder: (BuildContext context) { const String character = '骨'; - final TextStyle style = Theme.of(context)!.textTheme.headline2!; + final TextStyle style = Theme.of(context).textTheme.headline2!; return Scaffold( body: Container( padding: const EdgeInsets.all(48.0), @@ -118,7 +118,7 @@ void main() { home: Builder( builder: (BuildContext context) { const String character = '骨'; - final TextStyle style = Theme.of(context)!.textTheme.headline2!; + final TextStyle style = Theme.of(context).textTheme.headline2!; return Scaffold( body: Container( padding: const EdgeInsets.all(48.0), diff --git a/packages/flutter/test/widgets/inherited_model_test.dart b/packages/flutter/test/widgets/inherited_model_test.dart index 0239b5925cc..f06dfc0cf69 100644 --- a/packages/flutter/test/widgets/inherited_model_test.dart +++ b/packages/flutter/test/widgets/inherited_model_test.dart @@ -227,7 +227,7 @@ void main() { final Widget showABC = Builder( builder: (BuildContext context) { final ABCModel abc = ABCModel.of(context)!; - return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context)!.textTheme.headline6); + return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context).textTheme.headline6); } ); @@ -344,7 +344,7 @@ void main() { final Widget showABC = Builder( builder: (BuildContext context) { final ABCModel abc = ABCModel.of(context)!; - return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context)!.textTheme.headline6); + return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context).textTheme.headline6); } ); diff --git a/packages/flutter/test/widgets/list_view_viewporting_test.dart b/packages/flutter/test/widgets/list_view_viewporting_test.dart index 2a0e0607d78..5da1c7952bc 100644 --- a/packages/flutter/test/widgets/list_view_viewporting_test.dart +++ b/packages/flutter/test/widgets/list_view_viewporting_test.dart @@ -238,7 +238,7 @@ void main() { key: ValueKey(index), width: 500.0, // this should be ignored height: 220.0, - color: Theme.of(context)!.primaryColor, + color: Theme.of(context).primaryColor, child: Text('$index', textDirection: TextDirection.ltr), ); }; diff --git a/packages/flutter/test/widgets/navigator_test.dart b/packages/flutter/test/widgets/navigator_test.dart index 08d4ab5b941..13765085035 100644 --- a/packages/flutter/test/widgets/navigator_test.dart +++ b/packages/flutter/test/widgets/navigator_test.dart @@ -86,7 +86,7 @@ class OnTapPage extends StatelessWidget { behavior: HitTestBehavior.opaque, child: Container( child: Center( - child: Text(id, style: Theme.of(context)!.textTheme.headline3), + child: Text(id, style: Theme.of(context).textTheme.headline3), ), ), ), diff --git a/packages/flutter/test/widgets/route_notification_messages_test.dart b/packages/flutter/test/widgets/route_notification_messages_test.dart index 3542d527d43..74807990aeb 100644 --- a/packages/flutter/test/widgets/route_notification_messages_test.dart +++ b/packages/flutter/test/widgets/route_notification_messages_test.dart @@ -26,7 +26,7 @@ class OnTapPage extends StatelessWidget { behavior: HitTestBehavior.opaque, child: Container( child: Center( - child: Text(id, style: Theme.of(context)!.textTheme.headline3), + child: Text(id, style: Theme.of(context).textTheme.headline3), ), ), ),