diff --git a/dev/benchmarks/complex_layout/lib/main.dart b/dev/benchmarks/complex_layout/lib/main.dart index 634be4517c..26bef948b5 100644 --- a/dev/benchmarks/complex_layout/lib/main.dart +++ b/dev/benchmarks/complex_layout/lib/main.dart @@ -17,7 +17,7 @@ class ComplexLayoutApp extends StatefulWidget { @override ComplexLayoutAppState createState() => ComplexLayoutAppState(); - static ComplexLayoutAppState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher()); + static ComplexLayoutAppState of(BuildContext context) => context.findAncestorStateOfType(); } class ComplexLayoutAppState extends State { @@ -84,7 +84,7 @@ class ComplexLayout extends StatefulWidget { @override ComplexLayoutState createState() => ComplexLayoutState(); - static ComplexLayoutState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher()); + static ComplexLayoutState of(BuildContext context) => context.findAncestorStateOfType(); } class ComplexLayoutState extends State { diff --git a/examples/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart b/examples/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart index 72047eb684..df8f947fa8 100644 --- a/examples/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart +++ b/examples/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart @@ -50,9 +50,7 @@ class ExpandingBottomSheet extends StatefulWidget { static _ExpandingBottomSheetState of(BuildContext context, {bool isNullOk = false}) { assert(isNullOk != null); assert(context != null); - final _ExpandingBottomSheetState result = context.ancestorStateOfType( - const TypeMatcher<_ExpandingBottomSheetState>() - ); + final _ExpandingBottomSheetState result = context.findAncestorStateOfType<_ExpandingBottomSheetState>(); if (isNullOk || result != null) { return result; } diff --git a/packages/flutter/lib/src/cupertino/interface_level.dart b/packages/flutter/lib/src/cupertino/interface_level.dart index 685f35f7a3..7cc67c95ab 100644 --- a/packages/flutter/lib/src/cupertino/interface_level.dart +++ b/packages/flutter/lib/src/cupertino/interface_level.dart @@ -60,7 +60,7 @@ class CupertinoUserInterfaceLevel extends InheritedWidget { static CupertinoUserInterfaceLevelData of(BuildContext context, { bool nullOk = false }) { assert(context != null); assert(nullOk != null); - final CupertinoUserInterfaceLevel query = context.inheritFromWidgetOfExactType(CupertinoUserInterfaceLevel); + final CupertinoUserInterfaceLevel query = context.dependOnInheritedWidgetOfExactType(); if (query != null) return query._data; if (nullOk) diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 486c866721..e0edbd6593 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -2042,9 +2042,7 @@ class _NavigationBarComponentsTransition { } final RenderAnimatedOpacity topBackLabelOpacity = - topComponents.backLabelKey.currentContext?.ancestorRenderObjectOfType( - const TypeMatcher() - ); + topComponents.backLabelKey.currentContext?.findAncestorRenderObjectOfType(); Animation midClickOpacity; if (topBackLabelOpacity != null && topBackLabelOpacity.opacity.value < 1.0) { diff --git a/packages/flutter/lib/src/cupertino/refresh.dart b/packages/flutter/lib/src/cupertino/refresh.dart index 286b2d3d0a..eb270b84be 100644 --- a/packages/flutter/lib/src/cupertino/refresh.dart +++ b/packages/flutter/lib/src/cupertino/refresh.dart @@ -353,8 +353,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget { /// state that gets passed into the [builder] function. Used for testing. @visibleForTesting static RefreshIndicatorMode state(BuildContext context) { - final _CupertinoSliverRefreshControlState state - = context.ancestorStateOfType(const TypeMatcher<_CupertinoSliverRefreshControlState>()); + final _CupertinoSliverRefreshControlState state = context.findAncestorStateOfType<_CupertinoSliverRefreshControlState>(); return state.refreshState; } diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index 5d95cf0848..29a4668c7f 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -67,7 +67,7 @@ class CupertinoTheme extends StatelessWidget { /// Resolves all the colors defined in that [CupertinoThemeData] against the /// given [BuildContext] on a best-effort basis. static CupertinoThemeData of(BuildContext context) { - final _InheritedCupertinoTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedCupertinoTheme); + final _InheritedCupertinoTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); return (inheritedTheme?.theme?.data ?? const CupertinoThemeData()).resolveFrom(context, nullOk: true); } @@ -80,7 +80,7 @@ class CupertinoTheme extends StatelessWidget { /// Throws an exception if no such [CupertinoTheme] or [MediaQuery] widgets exist /// in the ancestry tree, unless [nullOk] is set to true. static Brightness brightnessOf(BuildContext context, { bool nullOk = false }) { - final _InheritedCupertinoTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedCupertinoTheme); + final _InheritedCupertinoTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedCupertinoTheme>(); return inheritedTheme?.theme?.data?._brightness ?? MediaQuery.of(context, nullOk: nullOk)?.platformBrightness; } diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index 6559a07d83..eff2e1280d 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -609,7 +609,7 @@ String _defaultApplicationName(BuildContext context) { // someone really wants their application title to change dynamically, they // can provide an explicit applicationName to the widgets defined in this // file, instead of relying on the default. - final Title ancestorTitle = context.ancestorWidgetOfExactType(Title); + final Title ancestorTitle = context.findAncestorWidgetOfExactType(); return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last; } diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 21d111e5db..18961ed72e 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -646,7 +646,7 @@ class _FloatingAppBarState extends State<_FloatingAppBar> { } RenderSliverFloatingPersistentHeader _headerRenderer() { - return context.ancestorRenderObjectOfType(const TypeMatcher<RenderSliverFloatingPersistentHeader>()); + return context.findAncestorRenderObjectOfType<RenderSliverFloatingPersistentHeader>(); } void _isScrollingListener() { diff --git a/packages/flutter/lib/src/material/banner_theme.dart b/packages/flutter/lib/src/material/banner_theme.dart index 7ab74c84b0..795c3c8e5b 100644 --- a/packages/flutter/lib/src/material/banner_theme.dart +++ b/packages/flutter/lib/src/material/banner_theme.dart @@ -140,13 +140,13 @@ class MaterialBannerTheme extends InheritedTheme { /// MaterialBannerThemeData theme = MaterialBannerTheme.of(context); /// ``` static MaterialBannerThemeData of(BuildContext context) { - final MaterialBannerTheme bannerTheme = context.inheritFromWidgetOfExactType(MaterialBannerTheme); + final MaterialBannerTheme bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>(); return bannerTheme?.data ?? Theme.of(context).bannerTheme; } @override Widget wrap(BuildContext context, Widget child) { - final MaterialBannerTheme ancestorTheme = context.ancestorWidgetOfExactType(MaterialBannerTheme); + final MaterialBannerTheme ancestorTheme = context.findAncestorWidgetOfExactType<MaterialBannerTheme>(); return identical(this, ancestorTheme) ? child : MaterialBannerTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/button_bar_theme.dart b/packages/flutter/lib/src/material/button_bar_theme.dart index b2bc04a4fc..ca342dd3e3 100644 --- a/packages/flutter/lib/src/material/button_bar_theme.dart +++ b/packages/flutter/lib/src/material/button_bar_theme.dart @@ -231,7 +231,7 @@ class ButtonBarTheme extends InheritedWidget { /// ButtonBarThemeData theme = ButtonBarTheme.of(context); /// ``` static ButtonBarThemeData of(BuildContext context) { - final ButtonBarTheme buttonBarTheme = context.inheritFromWidgetOfExactType(ButtonBarTheme); + final ButtonBarTheme buttonBarTheme = context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>(); return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme; } diff --git a/packages/flutter/lib/src/material/button_theme.dart b/packages/flutter/lib/src/material/button_theme.dart index 512519d530..eacab78ff8 100644 --- a/packages/flutter/lib/src/material/button_theme.dart +++ b/packages/flutter/lib/src/material/button_theme.dart @@ -218,7 +218,7 @@ class ButtonTheme extends InheritedTheme { /// ButtonThemeData theme = ButtonTheme.of(context); /// ``` static ButtonThemeData of(BuildContext context) { - final ButtonTheme inheritedButtonTheme = context.inheritFromWidgetOfExactType(ButtonTheme); + final ButtonTheme inheritedButtonTheme = context.dependOnInheritedWidgetOfExactType<ButtonTheme>(); ButtonThemeData buttonTheme = inheritedButtonTheme?.data; if (buttonTheme?.colorScheme == null) { // if buttonTheme or buttonTheme.colorScheme is null final ThemeData theme = Theme.of(context); @@ -235,7 +235,7 @@ class ButtonTheme extends InheritedTheme { @override Widget wrap(BuildContext context, Widget child) { - final ButtonTheme ancestorTheme = context.ancestorWidgetOfExactType(ButtonTheme); + final ButtonTheme ancestorTheme = context.findAncestorWidgetOfExactType<ButtonTheme>(); return identical(this, ancestorTheme) ? child : ButtonTheme.fromButtonThemeData(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/chip_theme.dart b/packages/flutter/lib/src/material/chip_theme.dart index dc0ad480c1..af7b617132 100644 --- a/packages/flutter/lib/src/material/chip_theme.dart +++ b/packages/flutter/lib/src/material/chip_theme.dart @@ -85,13 +85,13 @@ class ChipTheme extends InheritedTheme { /// * [ChipThemeData], which describes the actual configuration of a chip /// theme. static ChipThemeData of(BuildContext context) { - final ChipTheme inheritedTheme = context.inheritFromWidgetOfExactType(ChipTheme); + final ChipTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<ChipTheme>(); return inheritedTheme?.data ?? Theme.of(context).chipTheme; } @override Widget wrap(BuildContext context, Widget child) { - final ChipTheme ancestorTheme = context.ancestorWidgetOfExactType(ChipTheme); + final ChipTheme ancestorTheme = context.findAncestorWidgetOfExactType<ChipTheme>(); return identical(this, ancestorTheme) ? child : ChipTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/debug.dart b/packages/flutter/lib/src/material/debug.dart index beeb7ecc6f..8858c25890 100644 --- a/packages/flutter/lib/src/material/debug.dart +++ b/packages/flutter/lib/src/material/debug.dart @@ -24,7 +24,7 @@ import 'scaffold.dart' show Scaffold; /// Does nothing if asserts are disabled. Always returns true. bool debugCheckHasMaterial(BuildContext context) { assert(() { - if (context.widget is! Material && context.ancestorWidgetOfExactType(Material) == null) { + if (context.widget is! Material && context.findAncestorWidgetOfExactType<Material>() == null) { throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('No Material widget found.'), ErrorDescription( @@ -108,7 +108,7 @@ bool debugCheckHasMaterialLocalizations(BuildContext context) { /// Does nothing if asserts are disabled. Always returns true. bool debugCheckHasScaffold(BuildContext context) { assert(() { - if (context.widget is! Scaffold && context.ancestorWidgetOfExactType(Scaffold) == null) { + if (context.widget is! Scaffold && context.findAncestorWidgetOfExactType<Scaffold>() == null) { throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('No Scaffold widget found.'), ErrorDescription('${context.widget.runtimeType} widgets require a Scaffold widget ancestor.'), diff --git a/packages/flutter/lib/src/material/divider_theme.dart b/packages/flutter/lib/src/material/divider_theme.dart index 2c97f6db8c..a460403bff 100644 --- a/packages/flutter/lib/src/material/divider_theme.dart +++ b/packages/flutter/lib/src/material/divider_theme.dart @@ -159,13 +159,13 @@ class DividerTheme extends InheritedTheme { /// DividerThemeData theme = DividerTheme.of(context); /// ``` static DividerThemeData of(BuildContext context) { - final DividerTheme dividerTheme = context.inheritFromWidgetOfExactType(DividerTheme); + final DividerTheme dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>(); return dividerTheme?.data ?? Theme.of(context).dividerTheme; } @override Widget wrap(BuildContext context, Widget child) { - final DividerTheme ancestorTheme = context.ancestorWidgetOfExactType(DividerTheme); + final DividerTheme ancestorTheme = context.findAncestorWidgetOfExactType<DividerTheme>(); return identical(this, ancestorTheme) ? child : DividerTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 561cbf2245..e143fb6df5 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -687,7 +687,7 @@ class DropdownButtonHideUnderline extends InheritedWidget { /// Returns whether the underline of [DropdownButton] widgets should /// be hidden. static bool at(BuildContext context) { - return context.inheritFromWidgetOfExactType(DropdownButtonHideUnderline) != null; + return context.dependOnInheritedWidgetOfExactType<DropdownButtonHideUnderline>() != null; } @override diff --git a/packages/flutter/lib/src/material/flexible_space_bar.dart b/packages/flutter/lib/src/material/flexible_space_bar.dart index 124cd20ac9..910e495528 100644 --- a/packages/flutter/lib/src/material/flexible_space_bar.dart +++ b/packages/flutter/lib/src/material/flexible_space_bar.dart @@ -275,7 +275,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> { Widget build(BuildContext context) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { - final FlexibleSpaceBarSettings settings = context.inheritFromWidgetOfExactType(FlexibleSpaceBarSettings); + final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>(); assert( settings != null, 'A FlexibleSpaceBar must be wrapped in the widget returned by FlexibleSpaceBar.createSettings().', diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 79ccea3828..5a9b6d907f 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1848,7 +1848,7 @@ class InputDecorator extends StatefulWidget { /// /// [TextField] renders ink splashes within the container. static RenderBox containerOf(BuildContext context) { - final _RenderDecoration result = context.ancestorRenderObjectOfType(const TypeMatcher<_RenderDecoration>()); + final _RenderDecoration result = context.findAncestorRenderObjectOfType<_RenderDecoration>(); return result?.container; } diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index ba9dd54c4e..a755517cba 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -111,13 +111,13 @@ class ListTileTheme extends InheritedTheme { /// ListTileTheme theme = ListTileTheme.of(context); /// ``` static ListTileTheme of(BuildContext context) { - final ListTileTheme result = context.inheritFromWidgetOfExactType(ListTileTheme); + final ListTileTheme result = context.dependOnInheritedWidgetOfExactType<ListTileTheme>(); return result ?? const ListTileTheme(); } @override Widget wrap(BuildContext context, Widget child) { - final ListTileTheme ancestorTheme = context.ancestorWidgetOfExactType(ListTileTheme); + final ListTileTheme ancestorTheme = context.findAncestorWidgetOfExactType<ListTileTheme>(); return identical(this, ancestorTheme) ? child : ListTileTheme( dense: dense, style: style, diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index d2f733c9dd..3e2e1da8b0 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -292,7 +292,7 @@ class Material extends StatefulWidget { /// MaterialInkController inkController = Material.of(context); /// ``` static MaterialInkController of(BuildContext context) { - final _RenderInkFeatures result = context.ancestorRenderObjectOfType(const TypeMatcher<_RenderInkFeatures>()); + final _RenderInkFeatures result = context.findAncestorRenderObjectOfType<_RenderInkFeatures>(); return result; } diff --git a/packages/flutter/lib/src/material/popup_menu_theme.dart b/packages/flutter/lib/src/material/popup_menu_theme.dart index bb0738d0f0..b28a54ba09 100644 --- a/packages/flutter/lib/src/material/popup_menu_theme.dart +++ b/packages/flutter/lib/src/material/popup_menu_theme.dart @@ -145,13 +145,13 @@ class PopupMenuTheme extends InheritedTheme { /// PopupMenuThemeData theme = PopupMenuTheme.of(context); /// ``` static PopupMenuThemeData of(BuildContext context) { - final PopupMenuTheme popupMenuTheme = context.inheritFromWidgetOfExactType(PopupMenuTheme); + final PopupMenuTheme popupMenuTheme = context.dependOnInheritedWidgetOfExactType<PopupMenuTheme>(); return popupMenuTheme?.data ?? Theme.of(context).popupMenuTheme; } @override Widget wrap(BuildContext context, Widget child) { - final PopupMenuTheme ancestorTheme = context.ancestorWidgetOfExactType(PopupMenuTheme); + final PopupMenuTheme ancestorTheme = context.findAncestorWidgetOfExactType<PopupMenuTheme>(); return identical(this, ancestorTheme) ? child : PopupMenuTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index dae502943a..b7e15a3f28 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -1310,7 +1310,7 @@ class Scaffold extends StatefulWidget { static ScaffoldState of(BuildContext context, { bool nullOk = false }) { assert(nullOk != null); assert(context != null); - final ScaffoldState result = context.ancestorStateOfType(const TypeMatcher<ScaffoldState>()); + final ScaffoldState result = context.findAncestorStateOfType<ScaffoldState>(); if (nullOk || result != null) return result; throw FlutterError.fromParts(<DiagnosticsNode>[ @@ -1362,7 +1362,7 @@ class Scaffold extends StatefulWidget { /// the listener, and register a listener to the new [ScaffoldGeometry] /// listenable. static ValueListenable<ScaffoldGeometry> geometryOf(BuildContext context) { - final _ScaffoldScope scaffoldScope = context.inheritFromWidgetOfExactType(_ScaffoldScope); + final _ScaffoldScope scaffoldScope = context.dependOnInheritedWidgetOfExactType<_ScaffoldScope>(); if (scaffoldScope == null) throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary( @@ -1406,10 +1406,10 @@ class Scaffold extends StatefulWidget { assert(registerForUpdates != null); assert(context != null); if (registerForUpdates) { - final _ScaffoldScope scaffold = context.inheritFromWidgetOfExactType(_ScaffoldScope); + final _ScaffoldScope scaffold = context.dependOnInheritedWidgetOfExactType<_ScaffoldScope>(); return scaffold?.hasDrawer ?? false; } else { - final ScaffoldState scaffold = context.ancestorStateOfType(const TypeMatcher<ScaffoldState>()); + final ScaffoldState scaffold = context.findAncestorStateOfType<ScaffoldState>(); return scaffold?.hasDrawer ?? false; } } diff --git a/packages/flutter/lib/src/material/slider_theme.dart b/packages/flutter/lib/src/material/slider_theme.dart index 52282c19ec..5ad42e3586 100644 --- a/packages/flutter/lib/src/material/slider_theme.dart +++ b/packages/flutter/lib/src/material/slider_theme.dart @@ -185,13 +185,13 @@ class SliderTheme extends InheritedTheme { /// * [SliderThemeData], which describes the actual configuration of a slider /// theme. static SliderThemeData of(BuildContext context) { - final SliderTheme inheritedTheme = context.inheritFromWidgetOfExactType(SliderTheme); + final SliderTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<SliderTheme>(); return inheritedTheme != null ? inheritedTheme.data : Theme.of(context).sliderTheme; } @override Widget wrap(BuildContext context, Widget child) { - final SliderTheme ancestorTheme = context.ancestorWidgetOfExactType(SliderTheme); + final SliderTheme ancestorTheme = context.findAncestorWidgetOfExactType<SliderTheme>(); return identical(this, ancestorTheme) ? child : SliderTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index f0f4571a77..8099caa433 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -672,7 +672,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin { assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterialLocalizations(context)); assert(() { - if (context.ancestorWidgetOfExactType(Stepper) != null) + if (context.findAncestorWidgetOfExactType<Stepper>() != null) throw FlutterError( 'Steppers must not be nested.\n' 'The material specification advises that one should avoid embedding ' diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index f04d6f71a9..5c868e8d10 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart @@ -342,7 +342,7 @@ class DefaultTabController extends StatefulWidget { /// TabController controller = DefaultTabBarController.of(context); /// ``` static TabController of(BuildContext context) { - final _TabControllerScope scope = context.inheritFromWidgetOfExactType(_TabControllerScope); + final _TabControllerScope scope = context.dependOnInheritedWidgetOfExactType<_TabControllerScope>(); return scope?.controller; } diff --git a/packages/flutter/lib/src/material/theme.dart b/packages/flutter/lib/src/material/theme.dart index b088f0950b..7a4b563631 100644 --- a/packages/flutter/lib/src/material/theme.dart +++ b/packages/flutter/lib/src/material/theme.dart @@ -125,7 +125,7 @@ class Theme extends StatelessWidget { /// } /// ``` static ThemeData of(BuildContext context, { bool shadowThemeOnly = false }) { - final _InheritedTheme inheritedTheme = context.inheritFromWidgetOfExactType(_InheritedTheme); + final _InheritedTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>(); if (shadowThemeOnly) { if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme) return null; @@ -176,7 +176,7 @@ class _InheritedTheme extends InheritedTheme { @override Widget wrap(BuildContext context, Widget child) { - final _InheritedTheme ancestorTheme = context.ancestorWidgetOfExactType(_InheritedTheme); + final _InheritedTheme ancestorTheme = context.findAncestorWidgetOfExactType<_InheritedTheme>(); return identical(this, ancestorTheme) ? child : Theme(data: theme.data, child: child); } diff --git a/packages/flutter/lib/src/material/toggle_buttons_theme.dart b/packages/flutter/lib/src/material/toggle_buttons_theme.dart index 865667fbb4..546ac009e4 100644 --- a/packages/flutter/lib/src/material/toggle_buttons_theme.dart +++ b/packages/flutter/lib/src/material/toggle_buttons_theme.dart @@ -264,13 +264,13 @@ class ToggleButtonsTheme extends InheritedTheme { /// ToggleButtonsTheme theme = ToggleButtonsTheme.of(context); /// ``` static ToggleButtonsThemeData of(BuildContext context) { - final ToggleButtonsTheme toggleButtonsTheme = context.inheritFromWidgetOfExactType(ToggleButtonsTheme); + final ToggleButtonsTheme toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType<ToggleButtonsTheme>(); return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme; } @override Widget wrap(BuildContext context, Widget child) { - final ToggleButtonsTheme ancestorTheme = context.ancestorWidgetOfExactType(ToggleButtonsTheme); + final ToggleButtonsTheme ancestorTheme = context.findAncestorWidgetOfExactType<ToggleButtonsTheme>(); return identical(this, ancestorTheme) ? child : ToggleButtonsTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/material/tooltip_theme.dart b/packages/flutter/lib/src/material/tooltip_theme.dart index 73ff97a0ef..d89bee23a7 100644 --- a/packages/flutter/lib/src/material/tooltip_theme.dart +++ b/packages/flutter/lib/src/material/tooltip_theme.dart @@ -237,13 +237,13 @@ class TooltipTheme extends InheritedTheme { /// TooltipThemeData theme = TooltipTheme.of(context); /// ``` static TooltipThemeData of(BuildContext context) { - final TooltipTheme tooltipTheme = context.inheritFromWidgetOfExactType(TooltipTheme); + final TooltipTheme tooltipTheme = context.dependOnInheritedWidgetOfExactType<TooltipTheme>(); return tooltipTheme?.data ?? Theme.of(context).tooltipTheme; } @override Widget wrap(BuildContext context, Widget child) { - final TooltipTheme ancestorTheme = context.ancestorWidgetOfExactType(TooltipTheme); + final TooltipTheme ancestorTheme = context.findAncestorWidgetOfExactType<TooltipTheme>(); return identical(this, ancestorTheme) ? child : TooltipTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/widgets/actions.dart b/packages/flutter/lib/src/widgets/actions.dart index 2b3f3df0fe..917f28fe79 100644 --- a/packages/flutter/lib/src/widgets/actions.dart +++ b/packages/flutter/lib/src/widgets/actions.dart @@ -249,8 +249,8 @@ class Actions extends InheritedWidget { /// The `context` argument must not be null. static ActionDispatcher of(BuildContext context, {bool nullOk = false}) { assert(context != null); - final InheritedElement inheritedElement = context.ancestorInheritedElementForWidgetOfExactType(Actions); - final Actions inherited = context.inheritFromElement(inheritedElement); + final InheritedElement inheritedElement = context.getElementForInheritedWidgetOfExactType<Actions>(); + final Actions inherited = context.dependOnInheritedElement(inheritedElement); assert(() { if (nullOk) { return true; diff --git a/packages/flutter/lib/src/widgets/animated_list.dart b/packages/flutter/lib/src/widgets/animated_list.dart index 99384e1283..85a7e63c84 100644 --- a/packages/flutter/lib/src/widgets/animated_list.dart +++ b/packages/flutter/lib/src/widgets/animated_list.dart @@ -388,7 +388,7 @@ class AnimatedList extends StatefulWidget { static AnimatedListState of(BuildContext context, { bool nullOk = false }) { assert(context != null); assert(nullOk != null); - final AnimatedListState result = context.ancestorStateOfType(const TypeMatcher<AnimatedListState>()); + final AnimatedListState result = context.findAncestorStateOfType<AnimatedListState>(); if (nullOk || result != null) return result; throw FlutterError.fromParts(<DiagnosticsNode>[ @@ -774,7 +774,7 @@ class SliverAnimatedList extends StatefulWidget { static SliverAnimatedListState of(BuildContext context, {bool nullOk = false}) { assert(context != null); assert(nullOk != null); - final SliverAnimatedListState result = context.ancestorStateOfType(const TypeMatcher<SliverAnimatedListState>()); + final SliverAnimatedListState result = context.findAncestorStateOfType<SliverAnimatedListState>(); if (nullOk || result != null) return result; throw FlutterError( diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index eb2150db1c..e9376248f0 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -107,7 +107,7 @@ class Directionality extends InheritedWidget { /// TextDirection textDirection = Directionality.of(context); /// ``` static TextDirection of(BuildContext context) { - final Directionality widget = context.inheritFromWidgetOfExactType(Directionality); + final Directionality widget = context.dependOnInheritedWidgetOfExactType<Directionality>(); return widget?.textDirection; } @@ -5444,7 +5444,7 @@ class DefaultAssetBundle extends InheritedWidget { /// AssetBundle bundle = DefaultAssetBundle.of(context); /// ``` static AssetBundle of(BuildContext context) { - final DefaultAssetBundle result = context.inheritFromWidgetOfExactType(DefaultAssetBundle); + final DefaultAssetBundle result = context.dependOnInheritedWidgetOfExactType<DefaultAssetBundle>(); return result?.bundle ?? rootBundle; } diff --git a/packages/flutter/lib/src/widgets/debug.dart b/packages/flutter/lib/src/widgets/debug.dart index e06f1251f6..c0db63d7d6 100644 --- a/packages/flutter/lib/src/widgets/debug.dart +++ b/packages/flutter/lib/src/widgets/debug.dart @@ -179,7 +179,7 @@ bool debugItemsHaveDuplicateKeys(Iterable<Widget> items) { /// Does nothing if asserts are disabled. Always returns true. bool debugCheckHasTable(BuildContext context) { assert(() { - if (context.widget is! Table && context.ancestorWidgetOfExactType(Table) == null) { + if (context.widget is! Table && context.findAncestorWidgetOfExactType<Table>() == null) { throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('No Table widget found.'), ErrorDescription('${context.widget.runtimeType} widgets require a Table widget ancestor.'), @@ -207,7 +207,7 @@ bool debugCheckHasTable(BuildContext context) { /// Does nothing if asserts are disabled. Always returns true. bool debugCheckHasMediaQuery(BuildContext context) { assert(() { - if (context.widget is! MediaQuery && context.ancestorWidgetOfExactType(MediaQuery) == null) { + if (context.widget is! MediaQuery && context.findAncestorWidgetOfExactType<MediaQuery>() == null) { throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('No MediaQuery widget found.'), ErrorDescription('${context.widget.runtimeType} widgets require a MediaQuery widget ancestor.'), @@ -239,7 +239,7 @@ bool debugCheckHasMediaQuery(BuildContext context) { /// Does nothing if asserts are disabled. Always returns true. bool debugCheckHasDirectionality(BuildContext context) { assert(() { - if (context.widget is! Directionality && context.ancestorWidgetOfExactType(Directionality) == null) { + if (context.widget is! Directionality && context.findAncestorWidgetOfExactType<Directionality>() == null) { throw FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('No Directionality widget found.'), ErrorDescription('${context.widget.runtimeType} widgets require a Directionality widget ancestor.\n'), diff --git a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart index bea9279524..f4ecc80321 100644 --- a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart +++ b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart @@ -540,7 +540,7 @@ class DraggableScrollableActuator extends StatelessWidget { /// some [DraggableScrollableSheet] is listening for updates, `false` /// otherwise. static bool reset(BuildContext context) { - final _InheritedResetNotifier notifier = context.inheritFromWidgetOfExactType(_InheritedResetNotifier); + final _InheritedResetNotifier notifier = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>(); if (notifier == null) { return false; } @@ -592,7 +592,7 @@ class _InheritedResetNotifier extends InheritedNotifier<_ResetNotifier> { /// /// Returns true if the notifier requested a reset, false otherwise. static bool shouldReset(BuildContext context) { - final InheritedWidget widget = context.inheritFromWidgetOfExactType(_InheritedResetNotifier); + final InheritedWidget widget = context.dependOnInheritedWidgetOfExactType<_InheritedResetNotifier>(); if (widget == null) { return false; } diff --git a/packages/flutter/lib/src/widgets/focus_scope.dart b/packages/flutter/lib/src/widgets/focus_scope.dart index 3c433727bf..0eded03560 100644 --- a/packages/flutter/lib/src/widgets/focus_scope.dart +++ b/packages/flutter/lib/src/widgets/focus_scope.dart @@ -266,7 +266,7 @@ class Focus extends StatefulWidget { assert(context != null); assert(nullOk != null); assert(scopeOk != null); - final _FocusMarker marker = context.inheritFromWidgetOfExactType(_FocusMarker); + final _FocusMarker marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>(); final FocusNode node = marker?.notifier; if (node == null) { if (!nullOk) { @@ -538,7 +538,7 @@ class FocusScope extends Focus { /// The [context] argument must not be null. static FocusScopeNode of(BuildContext context) { assert(context != null); - final _FocusMarker marker = context.inheritFromWidgetOfExactType(_FocusMarker); + final _FocusMarker marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>(); return marker?.notifier?.nearestScope ?? context.owner.focusManager.rootScope; } diff --git a/packages/flutter/lib/src/widgets/focus_traversal.dart b/packages/flutter/lib/src/widgets/focus_traversal.dart index b15ae7651a..1753876fa0 100644 --- a/packages/flutter/lib/src/widgets/focus_traversal.dart +++ b/packages/flutter/lib/src/widgets/focus_traversal.dart @@ -868,7 +868,7 @@ class DefaultFocusTraversal extends InheritedWidget { /// The [context] argument must not be null. static FocusTraversalPolicy of(BuildContext context, { bool nullOk = false }) { assert(context != null); - final DefaultFocusTraversal inherited = context.inheritFromWidgetOfExactType(DefaultFocusTraversal); + final DefaultFocusTraversal inherited = context.dependOnInheritedWidgetOfExactType<DefaultFocusTraversal>(); assert(() { if (nullOk) { return true; diff --git a/packages/flutter/lib/src/widgets/form.dart b/packages/flutter/lib/src/widgets/form.dart index c18edfc455..ef29a52536 100644 --- a/packages/flutter/lib/src/widgets/form.dart +++ b/packages/flutter/lib/src/widgets/form.dart @@ -91,7 +91,7 @@ class Form extends StatefulWidget { /// form.save(); /// ``` static FormState of(BuildContext context) { - final _FormScope scope = context.inheritFromWidgetOfExactType(_FormScope); + final _FormScope scope = context.dependOnInheritedWidgetOfExactType<_FormScope>(); return scope?._formState; } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 2d78cd40fa..3440aba5d8 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -335,7 +335,14 @@ class GlobalObjectKey<T extends State<StatefulWidget>> extends GlobalKey<T> { } } -/// This class is a work-around for the "is" operator not accepting a variable value as its right operand +/// This class is a work-around for the "is" operator not accepting a variable value as its right operand. +/// +/// This class is deprecated. It will be deleted soon. +// TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 +@Deprecated( + 'TypeMatcher has been deprecated because it is no longer used in framework(only in deprecated methods). ' + 'This feature was deprecated after v1.12.1.' +) @optionalTypeArgs class TypeMatcher<T> { /// Creates a type matcher for the given type parameter. @@ -594,7 +601,7 @@ abstract class StatelessWidget extends Widget { /// * the fields of the widget, which themselves must not change over time, /// and /// * any ambient state obtained from the `context` using - /// [BuildContext.inheritFromWidgetOfExactType]. + /// [BuildContext.dependOnInheritedWidgetOfExactType]. /// /// If a widget's [build] method is to depend on anything else, use a /// [StatefulWidget] instead. @@ -877,7 +884,7 @@ typedef StateSetter = void Function(VoidCallback fn); /// called. /// * The framework calls [didChangeDependencies]. Subclasses of [State] should /// override [didChangeDependencies] to perform initialization involving -/// [InheritedWidget]s. If [BuildContext.inheritFromWidgetOfExactType] is +/// [InheritedWidget]s. If [BuildContext.dependOnInheritedWidgetOfExactType] is /// called, the [didChangeDependencies] method will be called again if the /// inherited widgets subsequently change or if the widget moves in the tree. /// * At this point, the [State] object is fully initialized and the framework @@ -1005,9 +1012,9 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable { /// /// {@endtemplate} /// - /// You cannot use [BuildContext.inheritFromWidgetOfExactType] from this + /// You cannot use [BuildContext.dependOnInheritedWidgetOfExactType] from this /// method. However, [didChangeDependencies] will be called immediately - /// following this method, and [BuildContext.inheritFromWidgetOfExactType] can + /// following this method, and [BuildContext.dependOnInheritedWidgetOfExactType] can /// be used there. /// /// If you override this, make sure your method starts with a call to @@ -1323,7 +1330,7 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable { /// method to notify this object about the change. /// /// This method is also called immediately after [initState]. It is safe to - /// call [BuildContext.inheritFromWidgetOfExactType] from this method. + /// call [BuildContext.dependOnInheritedWidgetOfExactType] from this method. /// /// Subclasses rarely override this method because the framework always /// calls [build] after a dependency changes. Some subclasses do override @@ -1517,7 +1524,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends ProxyWidge /// Base class for widgets that efficiently propagate information down the tree. /// /// To obtain the nearest instance of a particular type of inherited widget from -/// a build context, use [BuildContext.inheritFromWidgetOfExactType]. +/// a build context, use [BuildContext.dependOnInheritedWidgetOfExactType]. /// /// Inherited widgets, when referenced in this way, will cause the consumer to /// rebuild when the inherited widget itself changes state. @@ -1541,7 +1548,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends ProxyWidge /// final Color color; /// /// static FrogColor of(BuildContext context) { -/// return context.inheritFromWidgetOfExactType(FrogColor) as FrogColor; +/// return context.dependOnInheritedWidgetOfExactType<FrogColor>(); /// } /// /// @override @@ -1551,7 +1558,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends ProxyWidge /// {@end-tool} /// /// The convention is to provide a static method `of` on the [InheritedWidget] -/// which does the call to [BuildContext.inheritFromWidgetOfExactType]. This +/// which does the call to [BuildContext.dependOnInheritedWidgetOfExactType]. This /// allows the class to define its own fallback logic in case there isn't /// a widget in scope. In the example above, the value returned will be /// null in that case, but it could also have defaulted to a value. @@ -1564,7 +1571,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends ProxyWidge /// class, and is therefore private. The `of` method in that case is typically /// put on the public class instead. For example, [Theme] is implemented as a /// [StatelessWidget] that builds a private inherited widget; [Theme.of] looks -/// for that inherited widget using [BuildContext.inheritFromWidgetOfExactType] +/// for that inherited widget using [BuildContext.dependOnInheritedWidgetOfExactType] /// and then returns the [ThemeData]. /// /// {@youtube 560 315 https://www.youtube.com/watch?v=1t-8rBCGBYw} @@ -1917,18 +1924,29 @@ abstract class BuildContext { /// render object is usually short. Size get size; + /// Registers this build context with [ancestor] such that when + /// [ancestor]'s widget changes this build context is rebuilt. + /// + /// This method is deprecated. Please use [dependOnInheritedElement] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use dependOnInheritedElement instead. ' + 'This feature was deprecated after v1.12.1.' + ) + InheritedWidget inheritFromElement(InheritedElement ancestor, { Object aspect }); + /// Registers this build context with [ancestor] such that when /// [ancestor]'s widget changes this build context is rebuilt. /// /// Returns `ancestor.widget`. /// /// This method is rarely called directly. Most applications should use - /// [inheritFromWidgetOfExactType], which calls this method after finding + /// [dependOnInheritedWidgetOfExactType], which calls this method after finding /// the appropriate [InheritedElement] ancestor. /// - /// All of the qualifications about when [inheritFromWidgetOfExactType] can + /// All of the qualifications about when [dependOnInheritedWidgetOfExactType] can /// be called apply to this method as well. - InheritedWidget inheritFromElement(InheritedElement ancestor, { Object aspect }); + InheritedWidget dependOnInheritedElement(InheritedElement ancestor, { Object aspect }); /// Obtains the nearest widget of the given type, which must be the type of a /// concrete [InheritedWidget] subclass, and registers this build context with @@ -1936,6 +1954,20 @@ abstract class BuildContext { /// type is introduced, or the widget goes away), this build context is /// rebuilt so that it can obtain new values from that widget. /// + /// This method is deprecated. Please use [dependOnInheritedWidgetOfExactType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use dependOnInheritedWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + InheritedWidget inheritFromWidgetOfExactType(Type targetType, { Object aspect }); + + /// Obtains the nearest widget of the given type [T], which must be the type of a + /// concrete [InheritedWidget] subclass, and registers this build context with + /// that widget such that when that widget changes (or a new widget of that + /// type is introduced, or the widget goes away), this build context is + /// rebuilt so that it can obtain new values from that widget. + /// /// This is typically called implicitly from `of()` static methods, e.g. /// [Theme.of]. /// @@ -1965,32 +1997,54 @@ abstract class BuildContext { /// the widget or one of its ancestors is moved (for example, because an /// ancestor is added or removed). /// - /// The [aspect] parameter is only used when [targetType] is an + /// The [aspect] parameter is only used when [T] is an /// [InheritedWidget] subclasses that supports partial updates, like /// [InheritedModel]. It specifies what "aspect" of the inherited /// widget this context depends on. - InheritedWidget inheritFromWidgetOfExactType(Type targetType, { Object aspect }); + T dependOnInheritedWidgetOfExactType<T extends InheritedWidget>({ Object aspect }); /// Obtains the element corresponding to the nearest widget of the given type, /// which must be the type of a concrete [InheritedWidget] subclass. /// + /// This method is deprecated. Please use [getElementForInheritedWidgetOfExactType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use getElementForInheritedWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType); + + /// Obtains the element corresponding to the nearest widget of the given type [T], + /// which must be the type of a concrete [InheritedWidget] subclass. + /// /// Calling this method is O(1) with a small constant factor. /// /// This method does not establish a relationship with the target in the way - /// that [inheritFromWidgetOfExactType] does. + /// that [dependOnInheritedWidgetOfExactType] does. /// /// This method should not be called from [State.dispose] because the element /// tree is no longer stable at that time. To refer to an ancestor from that /// method, save a reference to the ancestor by calling - /// [inheritFromWidgetOfExactType] in [State.didChangeDependencies]. It is + /// [dependOnInheritedWidgetOfExactType] in [State.didChangeDependencies]. It is /// safe to use this method from [State.deactivate], which is called whenever /// the widget is removed from the tree. - InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType); + InheritedElement getElementForInheritedWidgetOfExactType<T extends InheritedWidget>(); /// Returns the nearest ancestor widget of the given type, which must be the /// type of a concrete [Widget] subclass. /// - /// In general, [inheritFromWidgetOfExactType] is more useful, since inherited + /// This method is deprecated. Please use [findAncestorWidgetOfExactType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + Widget ancestorWidgetOfExactType(Type targetType); + + /// Returns the nearest ancestor widget of the given type [T], which must be the + /// type of a concrete [Widget] subclass. + /// + /// In general, [dependOnInheritedWidgetOfExactType] is more useful, since inherited /// widgets will trigger consumers to rebuild when they change. This method is /// appropriate when used in interaction event handlers (e.g. gesture /// callbacks) or for performing one-off tasks such as asserting that you have @@ -2007,15 +2061,26 @@ abstract class BuildContext { /// This method should not be called from [State.deactivate] or [State.dispose] /// because the widget tree is no longer stable at that time. To refer to /// an ancestor from one of those methods, save a reference to the ancestor - /// by calling [ancestorWidgetOfExactType] in [State.didChangeDependencies]. - Widget ancestorWidgetOfExactType(Type targetType); + /// by calling [findAncestorWidgetOfExactType] in [State.didChangeDependencies]. + T findAncestorWidgetOfExactType<T extends Widget>(); /// Returns the [State] object of the nearest ancestor [StatefulWidget] widget /// that matches the given [TypeMatcher]. /// + /// This method is deprecated. Please use [findAncestorStateOfType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorStateOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + State ancestorStateOfType(TypeMatcher matcher); + + /// Returns the [State] object of the nearest ancestor [StatefulWidget] widget + /// that is an instance of the given type [T]. + /// /// This should not be used from build methods, because the build context will /// not be rebuilt if the value that would be returned by this method changes. - /// In general, [inheritFromWidgetOfExactType] is more appropriate for such + /// In general, [dependOnInheritedWidgetOfExactType] is more appropriate for such /// cases. This method is useful for changing the state of an ancestor widget in /// a one-off manner, for example, to cause an ancestor scrolling list to /// scroll this build context's widget into view, or to move the focus in @@ -2033,35 +2098,55 @@ abstract class BuildContext { /// This method should not be called from [State.deactivate] or [State.dispose] /// because the widget tree is no longer stable at that time. To refer to /// an ancestor from one of those methods, save a reference to the ancestor - /// by calling [ancestorStateOfType] in [State.didChangeDependencies]. + /// by calling [findAncestorStateOfType] in [State.didChangeDependencies]. /// /// {@tool sample} /// /// ```dart - /// ScrollableState scrollable = context.ancestorStateOfType( - /// const TypeMatcher<ScrollableState>(), - /// ); + /// ScrollableState scrollable = context.findAncestorStateOfType<ScrollableState>(); /// ``` /// {@end-tool} - State ancestorStateOfType(TypeMatcher matcher); + T findAncestorStateOfType<T extends State>(); /// Returns the [State] object of the furthest ancestor [StatefulWidget] widget /// that matches the given [TypeMatcher]. /// - /// Functions the same way as [ancestorStateOfType] but keeps visiting subsequent - /// ancestors until there are none of the type matching [TypeMatcher] remaining. + /// This method is deprecated. Please use [findRootAncestorStateOfType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findRootAncestorStateOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + State rootAncestorStateOfType(TypeMatcher matcher); + + /// Returns the [State] object of the furthest ancestor [StatefulWidget] widget + /// that is an instance of the given type [T]. + /// + /// Functions the same way as [findAncestorStateOfType] but keeps visiting subsequent + /// ancestors until there are none of the type instance of [T] remaining. /// Then returns the last one found. /// /// This operation is O(N) as well though N is the entire widget tree rather than /// a subtree. - State rootAncestorStateOfType(TypeMatcher matcher); + T findRootAncestorStateOfType<T extends State>(); /// Returns the [RenderObject] object of the nearest ancestor [RenderObjectWidget] widget /// that matches the given [TypeMatcher]. /// + /// This method is deprecated. Please use [findAncestorRenderObjectOfType] instead. + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorRenderObjectOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) + RenderObject ancestorRenderObjectOfType(TypeMatcher matcher); + + /// Returns the [RenderObject] object of the nearest ancestor [RenderObjectWidget] widget + /// that is an instance of the given type [T]. + /// /// This should not be used from build methods, because the build context will /// not be rebuilt if the value that would be returned by this method changes. - /// In general, [inheritFromWidgetOfExactType] is more appropriate for such + /// In general, [dependOnInheritedWidgetOfExactType] is more appropriate for such /// cases. This method is useful only in esoteric cases where a widget needs /// to cause an ancestor to change its layout or paint behavior. For example, /// it is used by [Material] so that [InkWell] widgets can trigger the ink @@ -2074,8 +2159,8 @@ abstract class BuildContext { /// This method should not be called from [State.deactivate] or [State.dispose] /// because the widget tree is no longer stable at that time. To refer to /// an ancestor from one of those methods, save a reference to the ancestor - /// by calling [ancestorRenderObjectOfType] in [State.didChangeDependencies]. - RenderObject ancestorRenderObjectOfType(TypeMatcher matcher); + /// by calling [findAncestorRenderObjectOfType] in [State.didChangeDependencies]. + T findAncestorRenderObjectOfType<T extends RenderObject>(); /// Walks the ancestor chain, starting with the parent of this build context's /// widget, invoking the argument for each ancestor. The callback is given a @@ -2609,7 +2694,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { // Custom implementation of hash code optimized for the ".of" pattern used // with `InheritedWidgets`. // - // `Element.inheritFromWidgetOfExactType` relies heavily on hash-based + // `Element.dependOnInheritedWidgetOfExactType` relies heavily on hash-based // `Set` look-ups, putting this getter on the performance critical path. // // The value is designed to fit within the SMI representation. This makes @@ -3428,7 +3513,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { ), ErrorHint( 'To safely refer to a widget\'s ancestor in its dispose() method, ' - 'save a reference to the ancestor by calling inheritFromWidgetOfExactType() ' + 'save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() ' 'in the widget\'s didChangeDependencies() method.' ), ]); @@ -3438,8 +3523,18 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return true; } + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use dependOnInheritedElement instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override InheritedWidget inheritFromElement(InheritedElement ancestor, { Object aspect }) { + return dependOnInheritedElement(ancestor, aspect: aspect); + } + + @override + InheritedWidget dependOnInheritedElement(InheritedElement ancestor, { Object aspect }) { assert(ancestor != null); _dependencies ??= HashSet<InheritedElement>(); _dependencies.add(ancestor); @@ -3447,6 +3542,11 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return ancestor.widget; } + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use dependOnInheritedWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override InheritedWidget inheritFromWidgetOfExactType(Type targetType, { Object aspect }) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3459,6 +3559,23 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return null; } + @override + T dependOnInheritedWidgetOfExactType<T extends InheritedWidget>({Object aspect}) { + assert(_debugCheckStateIsActiveForAncestorLookup()); + final InheritedElement ancestor = _inheritedWidgets == null ? null : _inheritedWidgets[T]; + if (ancestor != null) { + assert(ancestor is InheritedElement); + return dependOnInheritedElement(ancestor, aspect: aspect); + } + _hadUnsatisfiedDependencies = true; + return null; + } + + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use getElementForInheritedWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3466,11 +3583,23 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return ancestor; } + @override + InheritedElement getElementForInheritedWidgetOfExactType<T extends InheritedWidget>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + final InheritedElement ancestor = _inheritedWidgets == null ? null : _inheritedWidgets[T]; + return ancestor; + } + void _updateInheritance() { assert(_active); _inheritedWidgets = _parent?._inheritedWidgets; } + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorWidgetOfExactType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override Widget ancestorWidgetOfExactType(Type targetType) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3480,6 +3609,20 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return ancestor?.widget; } + @override + T findAncestorWidgetOfExactType<T extends Widget>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element ancestor = _parent; + while (ancestor != null && ancestor.widget.runtimeType != T) + ancestor = ancestor._parent; + return ancestor?.widget; + } + + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorStateOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override State ancestorStateOfType(TypeMatcher matcher) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3493,6 +3636,24 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return statefulAncestor?.state; } + @override + T findAncestorStateOfType<T extends State<StatefulWidget>>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element ancestor = _parent; + while (ancestor != null) { + if (ancestor is StatefulElement && ancestor.state is T) + break; + ancestor = ancestor._parent; + } + final StatefulElement statefulAncestor = ancestor; + return statefulAncestor?.state; + } + + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findRootAncestorStateOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override State rootAncestorStateOfType(TypeMatcher matcher) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3506,6 +3667,24 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return statefulAncestor?.state; } + @override + T findRootAncestorStateOfType<T extends State<StatefulWidget>>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element ancestor = _parent; + StatefulElement statefulAncestor; + while (ancestor != null) { + if (ancestor is StatefulElement && ancestor.state is T) + statefulAncestor = ancestor; + ancestor = ancestor._parent; + } + return statefulAncestor?.state; + } + + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use findAncestorRenderObjectOfType instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override RenderObject ancestorRenderObjectOfType(TypeMatcher matcher) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3519,6 +3698,19 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return renderObjectAncestor?.renderObject; } + @override + T findAncestorRenderObjectOfType<T extends RenderObject>() { + assert(_debugCheckStateIsActiveForAncestorLookup()); + Element ancestor = _parent; + while (ancestor != null) { + if (ancestor is RenderObjectElement && ancestor.renderObject is T) + break; + ancestor = ancestor._parent; + } + final RenderObjectElement renderObjectAncestor = ancestor; + return renderObjectAncestor?.renderObject; + } + @override void visitAncestorElements(bool visitor(Element element)) { assert(_debugCheckStateIsActiveForAncestorLookup()); @@ -3529,7 +3721,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { /// Called when a dependency of this element changes. /// - /// The [inheritFromWidgetOfExactType] registers this element as depending on + /// The [dependOnInheritedWidgetOfExactType] registers this element as depending on /// inherited information of the given type. When the information of that type /// changes at this location in the tree (e.g., because the [InheritedElement] /// updated to a new [InheritedWidget] and @@ -4256,14 +4448,24 @@ class StatefulElement extends ComponentElement { _state = null; } + // TODO(a14n): Remove this when it goes to stable, https://github.com/flutter/flutter/pull/44189 + @Deprecated( + 'Use dependOnInheritedElement instead. ' + 'This feature was deprecated after v1.12.1.' + ) @override InheritedWidget inheritFromElement(Element ancestor, { Object aspect }) { + return dependOnInheritedElement(ancestor, aspect: aspect); + } + + @override + InheritedWidget dependOnInheritedElement(Element ancestor, { Object aspect }) { assert(ancestor != null); assert(() { final Type targetType = ancestor.widget.runtimeType; if (state._debugLifecycleState == _StateLifecycle.created) { throw FlutterError.fromParts(<DiagnosticsNode>[ - ErrorSummary('inheritFromWidgetOfExactType($targetType) or inheritFromElement() was called before ${_state.runtimeType}.initState() completed.'), + ErrorSummary('dependOnInheritedWidgetOfExactType<$targetType>() or dependOnInheritedElement() was called before ${_state.runtimeType}.initState() completed.'), ErrorDescription( 'When an inherited widget changes, for example if the value of Theme.of() changes, ' 'its dependent widgets are rebuilt. If the dependent widget\'s reference to ' @@ -4280,24 +4482,24 @@ class StatefulElement extends ComponentElement { } if (state._debugLifecycleState == _StateLifecycle.defunct) { throw FlutterError.fromParts(<DiagnosticsNode>[ - ErrorSummary('inheritFromWidgetOfExactType($targetType) or inheritFromElement() was called after dispose(): $this'), + ErrorSummary('dependOnInheritedWidgetOfExactType<$targetType>() or dependOnInheritedElement() was called after dispose(): $this'), ErrorDescription( - 'This error happens if you call inheritFromWidgetOfExactType() on the ' + 'This error happens if you call dependOnInheritedWidgetOfExactType() on the ' 'BuildContext for a widget that no longer appears in the widget tree ' '(e.g., whose parent widget no longer includes the widget in its ' 'build). This error can occur when code calls ' - 'inheritFromWidgetOfExactType() from a timer or an animation callback.' + 'dependOnInheritedWidgetOfExactType() from a timer or an animation callback.' ), ErrorHint( 'The preferred solution is to cancel the timer or stop listening to the ' 'animation in the dispose() callback. Another solution is to check the ' '"mounted" property of this object before calling ' - 'inheritFromWidgetOfExactType() to ensure the object is still in the ' + 'dependOnInheritedWidgetOfExactType() to ensure the object is still in the ' 'tree.' ), ErrorHint( 'This error might indicate a memory leak if ' - 'inheritFromWidgetOfExactType() is being called because another object ' + 'dependOnInheritedWidgetOfExactType() is being called because another object ' 'is retaining a reference to this State object after it has been ' 'removed from the tree. To avoid memory leaks, consider breaking the ' 'reference to this object during dispose().' @@ -4306,7 +4508,7 @@ class StatefulElement extends ComponentElement { } return true; }()); - return super.inheritFromElement(ancestor, aspect: aspect); + return super.dependOnInheritedElement(ancestor, aspect: aspect); } @override @@ -4519,7 +4721,7 @@ class InheritedElement extends ProxyElement { /// See also: /// /// * [updateDependencies], which is called each time a dependency is - /// created with [inheritFromWidgetOfExactType]. + /// created with [dependOnInheritedWidgetOfExactType]. /// * [setDependencies], which sets dependencies value for a dependent /// element. /// * [notifyDependent], which can be overridden to use a dependent's @@ -4546,7 +4748,7 @@ class InheritedElement extends ProxyElement { /// See also: /// /// * [updateDependencies], which is called each time a dependency is - /// created with [inheritFromWidgetOfExactType]. + /// created with [dependOnInheritedWidgetOfExactType]. /// * [getDependencies], which returns the current value for a dependent /// element. /// * [notifyDependent], which can be overridden to use a dependent's @@ -4558,7 +4760,7 @@ class InheritedElement extends ProxyElement { _dependents[dependent] = value; } - /// Called by [inheritFromWidgetOfExactType] when a new [dependent] is added. + /// Called by [dependOnInheritedWidgetOfExactType] when a new [dependent] is added. /// /// Each dependent element can be mapped to a single object value with /// [setDependencies]. This method can lookup the existing dependencies with @@ -4595,7 +4797,7 @@ class InheritedElement extends ProxyElement { /// See also: /// /// * [updateDependencies], which is called each time a dependency is - /// created with [inheritFromWidgetOfExactType]. + /// created with [dependOnInheritedWidgetOfExactType]. /// * [getDependencies], which returns the current value for a dependent /// element. /// * [setDependencies], which sets the value for a dependent element. diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index aa7bdfeb48..50583e3c7d 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -371,7 +371,7 @@ class _HeroState extends State<Hero> { @override Widget build(BuildContext context) { assert( - context.ancestorWidgetOfExactType(Hero) == null, + context.findAncestorWidgetOfExactType<Hero>() == null, 'A Hero widget cannot be the descendant of another Hero widget.' ); diff --git a/packages/flutter/lib/src/widgets/icon_theme.dart b/packages/flutter/lib/src/widgets/icon_theme.dart index f74300fb08..6fddd12f35 100644 --- a/packages/flutter/lib/src/widgets/icon_theme.dart +++ b/packages/flutter/lib/src/widgets/icon_theme.dart @@ -70,7 +70,7 @@ class IconTheme extends InheritedTheme { } static IconThemeData _getInheritedIconThemeData(BuildContext context) { - final IconTheme iconTheme = context.inheritFromWidgetOfExactType(IconTheme); + final IconTheme iconTheme = context.dependOnInheritedWidgetOfExactType<IconTheme>(); return iconTheme?.data ?? const IconThemeData.fallback(); } @@ -79,7 +79,7 @@ class IconTheme extends InheritedTheme { @override Widget wrap(BuildContext context, Widget child) { - final IconTheme iconTheme = context.ancestorWidgetOfExactType(IconTheme); + final IconTheme iconTheme = context.findAncestorWidgetOfExactType<IconTheme>(); return identical(this, iconTheme) ? child : IconTheme(data: data, child: child); } diff --git a/packages/flutter/lib/src/widgets/inherited_model.dart b/packages/flutter/lib/src/widgets/inherited_model.dart index ed6dbe2517..a7ef992dfb 100644 --- a/packages/flutter/lib/src/widgets/inherited_model.dart +++ b/packages/flutter/lib/src/widgets/inherited_model.dart @@ -80,7 +80,7 @@ import 'framework.dart'; /// /// In the previous example the dependencies checked by /// [updateShouldNotifyDependent] are just the aspect strings passed to -/// `inheritFromWidgetOfExactType`. They're represented as a [Set] because +/// `dependOnInheritedWidgetOfExactType`. They're represented as a [Set] because /// one Widget can depend on more than one aspect of the model. /// If a widget depends on the model but doesn't specify an aspect, /// then changes in the model will cause the widget to be rebuilt @@ -120,7 +120,7 @@ abstract class InheritedModel<T> extends InheritedWidget { // The [result] will be a list of all of context's type T ancestors concluding // with the one that supports the specified model [aspect]. static void _findModels<T extends InheritedModel<Object>>(BuildContext context, Object aspect, List<InheritedElement> results) { - final InheritedElement model = context.ancestorInheritedElementForWidgetOfExactType(T); + final InheritedElement model = context.getElementForInheritedWidgetOfExactType<T>(); if (model == null) return; @@ -154,12 +154,12 @@ abstract class InheritedModel<T> extends InheritedWidget { /// returns true. /// /// If [aspect] is null this method is the same as - /// `context.inheritFromWidgetOfExactType(T)`. + /// `context.dependOnInheritedWidgetOfExactType<T>()`. /// /// If no ancestor of type T exists, null is returned. static T inheritFrom<T extends InheritedModel<Object>>(BuildContext context, { Object aspect }) { if (aspect == null) - return context.inheritFromWidgetOfExactType(T); + return context.dependOnInheritedWidgetOfExactType<T>(); // Create a dependency on all of the type T ancestor models up until // a model is found for which isSupportedAspect(aspect) is true. @@ -171,7 +171,7 @@ abstract class InheritedModel<T> extends InheritedWidget { final InheritedElement lastModel = models.last; for (InheritedElement model in models) { - final T value = context.inheritFromElement(model, aspect: aspect); + final T value = context.dependOnInheritedElement(model, aspect: aspect); if (model == lastModel) return value; } diff --git a/packages/flutter/lib/src/widgets/inherited_notifier.dart b/packages/flutter/lib/src/widgets/inherited_notifier.dart index 6c17e5eb74..441984dcbe 100644 --- a/packages/flutter/lib/src/widgets/inherited_notifier.dart +++ b/packages/flutter/lib/src/widgets/inherited_notifier.dart @@ -19,7 +19,7 @@ import 'framework.dart'; /// even if the [notifier] fires multiple times between two frames. /// /// Typically this class is subclassed with a class that provides an `of` static -/// method that calls [BuildContext.inheritFromWidgetOfExactType] with that +/// method that calls [BuildContext.dependOnInheritedWidgetOfExactType] with that /// class. /// /// The [updateShouldNotify] method may also be overridden, to change the logic diff --git a/packages/flutter/lib/src/widgets/inherited_theme.dart b/packages/flutter/lib/src/widgets/inherited_theme.dart index 9e8430018b..5b422471c5 100644 --- a/packages/flutter/lib/src/widgets/inherited_theme.dart +++ b/packages/flutter/lib/src/widgets/inherited_theme.dart @@ -101,7 +101,7 @@ abstract class InheritedTheme extends InheritedWidget { /// This implementation for [TooltipTheme] is typical: /// ```dart /// Widget wrap(BuildContext context, Widget child) { - /// final TooltipTheme ancestorTheme = context.ancestorWidgetOfExactType(TooltipTheme); + /// final TooltipTheme ancestorTheme = context.findAncestorWidgetOfExactType<TooltipTheme>()); /// return identical(this, ancestorTheme) ? child : TooltipTheme(data: data, child: child); /// } /// ``` diff --git a/packages/flutter/lib/src/widgets/localizations.dart b/packages/flutter/lib/src/widgets/localizations.dart index 0cc93a84e5..e17a2da11b 100644 --- a/packages/flutter/lib/src/widgets/localizations.dart +++ b/packages/flutter/lib/src/widgets/localizations.dart @@ -411,7 +411,7 @@ class Localizations extends StatefulWidget { static Locale localeOf(BuildContext context, { bool nullOk = false }) { assert(context != null); assert(nullOk != null); - final _LocalizationsScope scope = context.inheritFromWidgetOfExactType(_LocalizationsScope); + final _LocalizationsScope scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); if (nullOk && scope == null) return null; assert(scope != null, 'a Localizations ancestor was not found'); @@ -422,7 +422,7 @@ class Localizations extends StatefulWidget { // Localizations.override factory constructor. static List<LocalizationsDelegate<dynamic>> _delegatesOf(BuildContext context) { assert(context != null); - final _LocalizationsScope scope = context.inheritFromWidgetOfExactType(_LocalizationsScope); + final _LocalizationsScope scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); assert(scope != null, 'a Localizations ancestor was not found'); return List<LocalizationsDelegate<dynamic>>.from(scope.localizationsState.widget.delegates); } @@ -445,7 +445,7 @@ class Localizations extends StatefulWidget { static T of<T>(BuildContext context, Type type) { assert(context != null); assert(type != null); - final _LocalizationsScope scope = context.inheritFromWidgetOfExactType(_LocalizationsScope); + final _LocalizationsScope scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); return scope?.localizationsState?.resourcesFor<T>(type); } diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index 46c86fec5e..60bf360c4f 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -790,7 +790,7 @@ class MediaQuery extends InheritedWidget { static MediaQueryData of(BuildContext context, { bool nullOk = false }) { assert(context != null); assert(nullOk != null); - final MediaQuery query = context.inheritFromWidgetOfExactType(MediaQuery); + final MediaQuery query = context.dependOnInheritedWidgetOfExactType<MediaQuery>(); if (query != null) return query.data; if (nullOk) diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 2ede2fdfc2..d8fde91ed5 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -1488,8 +1488,8 @@ class Navigator extends StatefulWidget { bool nullOk = false, }) { final NavigatorState navigator = rootNavigator - ? context.rootAncestorStateOfType(const TypeMatcher<NavigatorState>()) - : context.ancestorStateOfType(const TypeMatcher<NavigatorState>()); + ? context.findRootAncestorStateOfType<NavigatorState>() + : context.findAncestorStateOfType<NavigatorState>(); assert(() { if (navigator == null && !nullOk) { throw FlutterError( @@ -2315,7 +2315,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { // If we're between frames (SchedulerPhase.idle) then absorb any // subsequent pointers from this frame. The absorbing flag will be // reset in the next frame, see build(). - final RenderAbsorbPointer absorber = _overlayKey.currentContext?.ancestorRenderObjectOfType(const TypeMatcher<RenderAbsorbPointer>()); + final RenderAbsorbPointer absorber = _overlayKey.currentContext?.findAncestorRenderObjectOfType<RenderAbsorbPointer>(); setState(() { absorber?.absorbing = true; // We do this in setState so that we'll reset the absorbing value back diff --git a/packages/flutter/lib/src/widgets/nested_scroll_view.dart b/packages/flutter/lib/src/widgets/nested_scroll_view.dart index 5b56c8d812..29bbaacd95 100644 --- a/packages/flutter/lib/src/widgets/nested_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/nested_scroll_view.dart @@ -266,7 +266,7 @@ class NestedScrollView extends StatefulWidget { /// For sample code showing how to use this method, see the [NestedScrollView] /// documentation. static SliverOverlapAbsorberHandle sliverOverlapAbsorberHandleFor(BuildContext context) { - final _InheritedNestedScrollView target = context.inheritFromWidgetOfExactType(_InheritedNestedScrollView); + final _InheritedNestedScrollView target = context.dependOnInheritedWidgetOfExactType<_InheritedNestedScrollView>(); assert(target != null, 'NestedScrollView.sliverOverlapAbsorberHandleFor must be called with a context that contains a NestedScrollView.'); return target.state._absorberHandle; } diff --git a/packages/flutter/lib/src/widgets/overlay.dart b/packages/flutter/lib/src/widgets/overlay.dart index 3edcbfd562..c4b2dcfef9 100644 --- a/packages/flutter/lib/src/widgets/overlay.dart +++ b/packages/flutter/lib/src/widgets/overlay.dart @@ -234,7 +234,7 @@ class Overlay extends StatefulWidget { /// OverlayState overlay = Overlay.of(context); /// ``` static OverlayState of(BuildContext context, { Widget debugRequiredFor }) { - final OverlayState result = context.ancestorStateOfType(const TypeMatcher<OverlayState>()); + final OverlayState result = context.findAncestorStateOfType<OverlayState>(); assert(() { if (debugRequiredFor != null && result == null) { final List<DiagnosticsNode> information = <DiagnosticsNode>[ diff --git a/packages/flutter/lib/src/widgets/page_storage.dart b/packages/flutter/lib/src/widgets/page_storage.dart index 93b801fae4..9d6cbd9368 100644 --- a/packages/flutter/lib/src/widgets/page_storage.dart +++ b/packages/flutter/lib/src/widgets/page_storage.dart @@ -161,7 +161,7 @@ class PageStorage extends StatelessWidget { /// PageStorageBucket bucket = PageStorage.of(context); /// ``` static PageStorageBucket of(BuildContext context) { - final PageStorage widget = context.ancestorWidgetOfExactType(PageStorage); + final PageStorage widget = context.findAncestorWidgetOfExactType<PageStorage>(); return widget?.bucket; } diff --git a/packages/flutter/lib/src/widgets/primary_scroll_controller.dart b/packages/flutter/lib/src/widgets/primary_scroll_controller.dart index b49912b65a..8354018edf 100644 --- a/packages/flutter/lib/src/widgets/primary_scroll_controller.dart +++ b/packages/flutter/lib/src/widgets/primary_scroll_controller.dart @@ -46,7 +46,7 @@ class PrimaryScrollController extends InheritedWidget { /// Returns null if there is no [ScrollController] associated with the given /// context. static ScrollController of(BuildContext context) { - final PrimaryScrollController result = context.inheritFromWidgetOfExactType(PrimaryScrollController); + final PrimaryScrollController result = context.dependOnInheritedWidgetOfExactType<PrimaryScrollController>(); return result?.controller; } diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index 4c013646bd..63e8ff9734 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -762,7 +762,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T /// (specifically, if [isCurrent] or [canPop] change value). @optionalTypeArgs static ModalRoute<T> of<T extends Object>(BuildContext context) { - final _ModalScopeStatus widget = context.inheritFromWidgetOfExactType(_ModalScopeStatus); + final _ModalScopeStatus widget = context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>(); return widget?.route; } diff --git a/packages/flutter/lib/src/widgets/scroll_configuration.dart b/packages/flutter/lib/src/widgets/scroll_configuration.dart index 43693e3240..4a67ffa70c 100644 --- a/packages/flutter/lib/src/widgets/scroll_configuration.dart +++ b/packages/flutter/lib/src/widgets/scroll_configuration.dart @@ -100,7 +100,7 @@ class ScrollConfiguration extends InheritedWidget { /// If no [ScrollConfiguration] widget is in scope of the given `context`, /// a default [ScrollBehavior] instance is returned. static ScrollBehavior of(BuildContext context) { - final ScrollConfiguration configuration = context.inheritFromWidgetOfExactType(ScrollConfiguration); + final ScrollConfiguration configuration = context.dependOnInheritedWidgetOfExactType<ScrollConfiguration>(); return configuration?.behavior ?? const ScrollBehavior(); } diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 2a5620829d..179703bec2 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -229,7 +229,7 @@ class Scrollable extends StatefulWidget { /// ScrollableState scrollable = Scrollable.of(context); /// ``` static ScrollableState of(BuildContext context) { - final _ScrollableScope widget = context.inheritFromWidgetOfExactType(_ScrollableScope); + final _ScrollableScope widget = context.dependOnInheritedWidgetOfExactType<_ScrollableScope>(); return widget?.scrollable; } diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 58df560bdb..f6600768d6 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -274,7 +274,7 @@ class Shortcuts extends StatefulWidget { /// The [context] argument must not be null. static ShortcutManager of(BuildContext context, {bool nullOk = false}) { assert(context != null); - final _ShortcutsMarker inherited = context.inheritFromWidgetOfExactType(_ShortcutsMarker); + final _ShortcutsMarker inherited = context.dependOnInheritedWidgetOfExactType<_ShortcutsMarker>(); assert(() { if (nullOk) { return true; diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index 60d8cec270..f622e53918 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -150,7 +150,7 @@ class DefaultTextStyle extends InheritedTheme { /// DefaultTextStyle style = DefaultTextStyle.of(context); /// ``` static DefaultTextStyle of(BuildContext context) { - return context.inheritFromWidgetOfExactType(DefaultTextStyle) ?? const DefaultTextStyle.fallback(); + return context.dependOnInheritedWidgetOfExactType<DefaultTextStyle>() ?? const DefaultTextStyle.fallback(); } @override @@ -165,7 +165,7 @@ class DefaultTextStyle extends InheritedTheme { @override Widget wrap(BuildContext context, Widget child) { - final DefaultTextStyle defaultTextStyle = context.ancestorWidgetOfExactType(DefaultTextStyle); + final DefaultTextStyle defaultTextStyle = context.findAncestorWidgetOfExactType<DefaultTextStyle>(); return identical(this, defaultTextStyle) ? child : DefaultTextStyle( style: style, textAlign: textAlign, diff --git a/packages/flutter/lib/src/widgets/ticker_provider.dart b/packages/flutter/lib/src/widgets/ticker_provider.dart index a7d50dac87..3b7c52001b 100644 --- a/packages/flutter/lib/src/widgets/ticker_provider.dart +++ b/packages/flutter/lib/src/widgets/ticker_provider.dart @@ -49,7 +49,7 @@ class TickerMode extends InheritedWidget { /// bool tickingEnabled = TickerMode.of(context); /// ``` static bool of(BuildContext context) { - final TickerMode widget = context.inheritFromWidgetOfExactType(TickerMode); + final TickerMode widget = context.dependOnInheritedWidgetOfExactType<TickerMode>(); return widget?.enabled ?? true; } diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index e03eedc9f6..633ef050aa 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -328,7 +328,7 @@ void main() { }); Iterable<double> opacities = titles.map<double>((Element element) { - final RenderAnimatedOpacity renderOpacity = element.ancestorRenderObjectOfType(const TypeMatcher<RenderAnimatedOpacity>()); + final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>(); return renderOpacity.opacity.value; }); @@ -353,7 +353,7 @@ void main() { }); opacities = titles.map<double>((Element element) { - final RenderAnimatedOpacity renderOpacity = element.ancestorRenderObjectOfType(const TypeMatcher<RenderAnimatedOpacity>()); + final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>(); return renderOpacity.opacity.value; }); @@ -461,7 +461,7 @@ void main() { expect(find.text('Different title'), findsOneWidget); RenderAnimatedOpacity largeTitleOpacity = - tester.element(find.text('Title')).ancestorRenderObjectOfType(const TypeMatcher<RenderAnimatedOpacity>()); + tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>(); // Large title initially visible. expect( largeTitleOpacity.opacity.value, @@ -469,7 +469,7 @@ void main() { ); // Middle widget not even wrapped with RenderOpacity, i.e. is always visible. expect( - tester.element(find.text('Different title')).ancestorRenderObjectOfType(const TypeMatcher<RenderOpacity>()), + tester.element(find.text('Different title')).findAncestorRenderObjectOfType<RenderOpacity>(), isNull, ); @@ -480,7 +480,7 @@ void main() { await tester.pump(const Duration(milliseconds: 300)); largeTitleOpacity = - tester.element(find.text('Title')).ancestorRenderObjectOfType(const TypeMatcher<RenderAnimatedOpacity>()); + tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>(); // Large title no longer visible. expect( largeTitleOpacity.opacity.value, diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index f33ef83766..b5ffa40bff 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_test.dart @@ -118,7 +118,7 @@ void main() { final Iterable<double> opacities = titles.map<double>((Element element) { final RenderAnimatedOpacity renderOpacity = - element.ancestorRenderObjectOfType(const TypeMatcher<RenderAnimatedOpacity>()); + element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>(); return renderOpacity.opacity.value; }); diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index a1303a4ecf..2fbd424494 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -735,9 +735,10 @@ void _tests() { ); final Finder chevronFinder = find.byType(IconButton); - final List<RenderAnimatedOpacity> chevronRenderers = chevronFinder.evaluate().map( - (Element element) => element.ancestorRenderObjectOfType( - const TypeMatcher<RenderAnimatedOpacity>())).cast<RenderAnimatedOpacity>().toList(); + final List<RenderAnimatedOpacity> chevronRenderers = chevronFinder + .evaluate() + .map((Element element) => element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>()) + .toList(); // Initial chevron animation state should be dismissed // An AlwaysStoppedAnimation is also found and is ignored diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 5295fb7282..e794753830 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -29,7 +29,7 @@ void main() { await tester.pump(const Duration(milliseconds: 1)); FadeTransition widget2Opacity = - tester.element(find.text('Page 2')).ancestorWidgetOfExactType(FadeTransition); + tester.element(find.text('Page 2')).findAncestorWidgetOfExactType<FadeTransition>(); Offset widget2TopLeft = tester.getTopLeft(find.text('Page 2')); final Size widget2Size = tester.getSize(find.text('Page 2')); @@ -53,7 +53,7 @@ void main() { await tester.pump(const Duration(milliseconds: 1)); widget2Opacity = - tester.element(find.text('Page 2')).ancestorWidgetOfExactType(FadeTransition); + tester.element(find.text('Page 2')).findAncestorWidgetOfExactType<FadeTransition>(); widget2TopLeft = tester.getTopLeft(find.text('Page 2')); // Page 2 starts to move down. @@ -94,7 +94,7 @@ void main() { Offset widget1TransientTopLeft = tester.getTopLeft(find.text('Page 1')); Offset widget2TopLeft = tester.getTopLeft(find.text('Page 2')); final RenderDecoratedBox box = tester.element(find.byKey(page2Key)) - .ancestorRenderObjectOfType(const TypeMatcher<RenderDecoratedBox>()); + .findAncestorRenderObjectOfType<RenderDecoratedBox>(); // Page 1 is moving to the left. expect(widget1TransientTopLeft.dx < widget1InitialTopLeft.dx, true); diff --git a/packages/flutter/test/material/reorderable_list_test.dart b/packages/flutter/test/material/reorderable_list_test.dart index 7d7629c75c..56c7adf2d0 100644 --- a/packages/flutter/test/material/reorderable_list_test.dart +++ b/packages/flutter/test/material/reorderable_list_test.dart @@ -186,10 +186,10 @@ void main() { testWidgets('Preserves children states when the list parent changes the order', (WidgetTester tester) async { _StatefulState findState(Key key) { - return find.byElementPredicate((Element element) => element.ancestorWidgetOfExactType(_Stateful)?.key == key) + return find.byElementPredicate((Element element) => element.findAncestorWidgetOfExactType<_Stateful>()?.key == key) .evaluate() .first - .ancestorStateOfType(const TypeMatcher<_StatefulState>()); + .findAncestorStateOfType<_StatefulState>(); } await tester.pumpWidget(MaterialApp( home: ReorderableListView( @@ -616,10 +616,10 @@ void main() { testWidgets('Preserves children states when the list parent changes the order', (WidgetTester tester) async { _StatefulState findState(Key key) { - return find.byElementPredicate((Element element) => element.ancestorWidgetOfExactType(_Stateful)?.key == key) + return find.byElementPredicate((Element element) => element.findAncestorWidgetOfExactType<_Stateful>()?.key == key) .evaluate() .first - .ancestorStateOfType(const TypeMatcher<_StatefulState>()); + .findAncestorStateOfType<_StatefulState>(); } await tester.pumpWidget(MaterialApp( home: ReorderableListView( diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index f2b81c27ee..ffc92bb923 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -1713,13 +1713,13 @@ void main() { // Toolbar should fade in. Starting at 0% opacity. final Element target = tester.element(find.text('SELECT ALL')); - final FadeTransition opacity = target.ancestorWidgetOfExactType(FadeTransition); + final FadeTransition opacity = target.findAncestorWidgetOfExactType<FadeTransition>(); expect(opacity, isNotNull); expect(opacity.opacity.value, equals(0.0)); // Still fading in. await tester.pump(const Duration(milliseconds: 50)); - final FadeTransition opacity2 = target.ancestorWidgetOfExactType(FadeTransition); + final FadeTransition opacity2 = target.findAncestorWidgetOfExactType<FadeTransition>(); expect(opacity, same(opacity2)); expect(opacity.opacity.value, greaterThan(0.0)); expect(opacity.opacity.value, lessThan(1.0)); diff --git a/packages/flutter/test/widgets/dispose_ancestor_lookup_test.dart b/packages/flutter/test/widgets/dispose_ancestor_lookup_test.dart index fdc8747078..02bb7f76aa 100644 --- a/packages/flutter/test/widgets/dispose_ancestor_lookup_test.dart +++ b/packages/flutter/test/widgets/dispose_ancestor_lookup_test.dart @@ -28,12 +28,12 @@ class TestWidgetState extends State<TestWidget> { } void main() { - testWidgets('inheritFromWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { + testWidgets('dependOnInheritedWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { bool disposeCalled = false; await tester.pumpWidget( TestWidget((BuildContext context) { disposeCalled = true; - context.inheritFromWidgetOfExactType(Container); + context.dependOnInheritedWidgetOfExactType<InheritedWidget>(); }), ); await tester.pumpWidget(Container()); @@ -41,12 +41,12 @@ void main() { expect(tester.takeException(), isFlutterError); }); - testWidgets('ancestorInheritedElementForWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { + testWidgets('getElementForInheritedWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { bool disposeCalled = false; await tester.pumpWidget( TestWidget((BuildContext context) { disposeCalled = true; - context.ancestorInheritedElementForWidgetOfExactType(Container); + context.getElementForInheritedWidgetOfExactType<InheritedWidget>(); }), ); await tester.pumpWidget(Container()); @@ -54,12 +54,12 @@ void main() { expect(tester.takeException(), isFlutterError); }); - testWidgets('ancestorWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { + testWidgets('findAncestorWidgetOfExactType() called from dispose() throws error', (WidgetTester tester) async { bool disposeCalled = false; await tester.pumpWidget( TestWidget((BuildContext context) { disposeCalled = true; - context.ancestorWidgetOfExactType(Container); + context.findAncestorWidgetOfExactType<Container>(); }), ); await tester.pumpWidget(Container()); @@ -67,12 +67,12 @@ void main() { expect(tester.takeException(), isFlutterError); }); - testWidgets('ancestorStateOfType() called from dispose() throws error', (WidgetTester tester) async { + testWidgets('findAncestorStateOfType() called from dispose() throws error', (WidgetTester tester) async { bool disposeCalled = false; await tester.pumpWidget( TestWidget((BuildContext context) { disposeCalled = true; - context.ancestorStateOfType(const TypeMatcher<Container>()); + context.findAncestorStateOfType<State>(); }), ); await tester.pumpWidget(Container()); @@ -80,12 +80,12 @@ void main() { expect(tester.takeException(), isFlutterError); }); - testWidgets('ancestorRenderObjectOfType() called from dispose() throws error', (WidgetTester tester) async { + testWidgets('findAncestorRenderObjectOfType() called from dispose() throws error', (WidgetTester tester) async { bool disposeCalled = false; await tester.pumpWidget( TestWidget((BuildContext context) { disposeCalled = true; - context.ancestorRenderObjectOfType(const TypeMatcher<Container>()); + context.findAncestorRenderObjectOfType<RenderObject>(); }), ); await tester.pumpWidget(Container()); diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index ac74d7c6d2..ef0949dd05 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -1589,8 +1589,7 @@ void main() { ), ); - final RenderEditable render = tester.allRenderObjects - .firstWhere((RenderObject o) => o.runtimeType == RenderEditable); + final RenderEditable render = tester.allRenderObjects.whereType<RenderEditable>().first; final int semanticsId = render.debugSemantics.id; expect(controller.selection.baseOffset, 4); @@ -1682,8 +1681,7 @@ void main() { ), ); - final RenderEditable render = tester.allRenderObjects - .firstWhere((RenderObject o) => o.runtimeType == RenderEditable); + final RenderEditable render = tester.allRenderObjects.whereType<RenderEditable>().first; final int semanticsId = render.debugSemantics.id; expect(controller.selection.baseOffset, 14); @@ -1784,8 +1782,7 @@ void main() { ), ); - final RenderEditable render = tester.allRenderObjects - .firstWhere((RenderObject o) => o.runtimeType == RenderEditable); + final RenderEditable render = tester.allRenderObjects.whereType<RenderEditable>().first; final int semanticsId = render.debugSemantics.id; expect(controller.selection.baseOffset, 4); @@ -1885,8 +1882,7 @@ void main() { ), ); - final RenderEditable render = tester.allRenderObjects - .firstWhere((RenderObject o) => o.runtimeType == RenderEditable); + final RenderEditable render = tester.allRenderObjects.whereType<RenderEditable>().first; final int semanticsId = render.debugSemantics.id; expect(controller.selection.baseOffset, 14); @@ -2311,8 +2307,7 @@ void main() { )); // Simulate selection change via tap to show handles. - final RenderEditable render = tester.allRenderObjects - .firstWhere((RenderObject o) => o.runtimeType == RenderEditable); + final RenderEditable render = tester.allRenderObjects.whereType<RenderEditable>().first; expect(render.text.style.fontStyle, FontStyle.italic); }); @@ -2798,8 +2793,8 @@ void main() { // Check that the animations are functional and going in the right // direction. - final List<Widget> transitions = - find.byType(FadeTransition).evaluate().map((Element e) => e.widget).toList(); + final List<FadeTransition> transitions = + find.byType(FadeTransition).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList(); // On Android, an empty app contains a single FadeTransition. The following // two are the left and right text selection handles, respectively. final FadeTransition left = transitions[1]; @@ -3637,8 +3632,8 @@ void main() { // Check that the animations are functional and going in the right // direction. - final List<Widget> transitions = - find.byType(FadeTransition).evaluate().map((Element e) => e.widget).toList(); + final List<FadeTransition> transitions = + find.byType(FadeTransition).evaluate().map((Element e) => e.widget).cast<FadeTransition>().toList(); final FadeTransition left = transitions[0]; final FadeTransition right = transitions[1]; diff --git a/packages/flutter/test/widgets/inherited_test.dart b/packages/flutter/test/widgets/inherited_test.dart index fe00bd8195..6d7a658d78 100644 --- a/packages/flutter/test/widgets/inherited_test.dart +++ b/packages/flutter/test/widgets/inherited_test.dart @@ -42,7 +42,7 @@ class ExpectFailState extends State<ExpectFail> { void initState() { super.initState(); try { - context.inheritFromWidgetOfExactType(TestInherited); // should fail + context.dependOnInheritedWidgetOfExactType<TestInherited>(); // should fail } catch (e) { widget.onError(); } @@ -63,7 +63,7 @@ void main() { final Builder builder = Builder( builder: (BuildContext context) { - log.add(context.inheritFromWidgetOfExactType(TestInherited)); + log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()); return Container(); } ); @@ -95,7 +95,7 @@ void main() { key: globalKey, child: Builder( builder: (BuildContext context) { - log.add(context.inheritFromWidgetOfExactType(TestInherited)); + log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()); return Container(); } ), @@ -132,7 +132,7 @@ void main() { child: Container( child: Builder( builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add('a: ${v.value}'); return const Text('', textDirection: TextDirection.ltr); } @@ -149,7 +149,7 @@ void main() { child: Container( child: Builder( builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add('b: ${v.value}'); return const Text('', textDirection: TextDirection.ltr); } @@ -207,7 +207,7 @@ void main() { key: key, child: Builder( builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add('a: ${v.value}'); return const Text('', textDirection: TextDirection.ltr); } @@ -225,7 +225,7 @@ void main() { key: key, child: Builder( builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add('b: ${v.value}'); return const Text('', textDirection: TextDirection.ltr); } @@ -268,7 +268,7 @@ void main() { final Widget child = Builder( builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add(v.value); return const Text('', textDirection: TextDirection.ltr); } @@ -339,7 +339,7 @@ void main() { final Widget child = Builder( key: GlobalKey(), builder: (BuildContext context) { - final ValueInherited v = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); log.add(v.value); return const Text('', textDirection: TextDirection.ltr); }, @@ -386,7 +386,7 @@ void main() { key: GlobalKey(), child: Builder( builder: (BuildContext context) { - final ValueInherited widget = context.inheritFromWidgetOfExactType(ValueInherited); + final ValueInherited widget = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); inheritedValue = widget?.value; return Container(); } @@ -444,7 +444,7 @@ void main() { shouldNotify: false, child: Builder( builder: (BuildContext context) { - context.inheritFromWidgetOfExactType(TestInherited); + context.dependOnInheritedWidgetOfExactType<TestInherited>(); buildCount += 1; return Container(); } @@ -484,7 +484,7 @@ void main() { final Widget builder = Builder( builder: (BuildContext context) { - context.inheritFromWidgetOfExactType(ChangeNotifierInherited); + context.dependOnInheritedWidgetOfExactType<ChangeNotifierInherited>(); buildCount += 1; return Container(); } diff --git a/packages/flutter/test/widgets/overlay_test.dart b/packages/flutter/test/widgets/overlay_test.dart index 484871cd5b..68e6f57b4c 100644 --- a/packages/flutter/test/widgets/overlay_test.dart +++ b/packages/flutter/test/widgets/overlay_test.dart @@ -19,7 +19,7 @@ void main() { OverlayEntry( builder: (BuildContext context) { didBuild = true; - final Overlay overlay = context.ancestorWidgetOfExactType(Overlay); + final Overlay overlay = context.findAncestorWidgetOfExactType<Overlay>(); expect(overlay, isNotNull); expect(overlay.key, equals(overlayKey)); return Container(); diff --git a/packages/flutter/test/widgets/page_forward_transitions_test.dart b/packages/flutter/test/widgets/page_forward_transitions_test.dart index 2c78b245ad..7188cc68aa 100644 --- a/packages/flutter/test/widgets/page_forward_transitions_test.dart +++ b/packages/flutter/test/widgets/page_forward_transitions_test.dart @@ -113,7 +113,7 @@ void main() { ) ); - final NavigatorState navigator = insideKey.currentContext.ancestorStateOfType(const TypeMatcher<NavigatorState>()); + final NavigatorState navigator = insideKey.currentContext.findAncestorStateOfType<NavigatorState>(); expect(state(), equals('BC')); // transition ->1 is at 1.0