Unverified Commit fcb40a05 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

make some BuildContext methods generics (#44189)

* make BuildContext.{ancestorStateOfType,ancestorRenderObjectOfType,rootAncestorStateOfType} generic

* make BuildContext.inheritFromWidgetOfExactType generic

* make BuildContext.ancestorInheritedElementForWidgetOfExactType generic

* make BuildContext.ancestorWidgetOfExactType generic

* fix snippet

* bump scoped_model on temp version

* update names

* Revert "bump scoped_model on temp version"

This reverts commit d1fcbba028cdb07f44738d1652391692d1ea5ec0.

* address review comments

* fix ci

* address review comments

* repeat the deprecation notice

* fix uppercase

* use of recommanded deprecation syntax

* address review comment
parent 7fcf0306
......@@ -17,7 +17,7 @@ class ComplexLayoutApp extends StatefulWidget {
@override
ComplexLayoutAppState createState() => ComplexLayoutAppState();
static ComplexLayoutAppState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher<ComplexLayoutAppState>());
static ComplexLayoutAppState of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutAppState>();
}
class ComplexLayoutAppState extends State<ComplexLayoutApp> {
......@@ -84,7 +84,7 @@ class ComplexLayout extends StatefulWidget {
@override
ComplexLayoutState createState() => ComplexLayoutState();
static ComplexLayoutState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher<ComplexLayoutState>());
static ComplexLayoutState of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutState>();
}
class ComplexLayoutState extends State<ComplexLayout> {
......
......@@ -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;
}
......
......@@ -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<CupertinoUserInterfaceLevel>();
if (query != null)
return query._data;
if (nullOk)
......
......@@ -2042,9 +2042,7 @@ class _NavigationBarComponentsTransition {
}
final RenderAnimatedOpacity topBackLabelOpacity =
topComponents.backLabelKey.currentContext?.ancestorRenderObjectOfType(
const TypeMatcher<RenderAnimatedOpacity>()
);
topComponents.backLabelKey.currentContext?.findAncestorRenderObjectOfType<RenderAnimatedOpacity>();
Animation<double> midClickOpacity;
if (topBackLabelOpacity != null && topBackLabelOpacity.opacity.value < 1.0) {
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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<Title>();
return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last;
}
......
......@@ -646,7 +646,7 @@ class _FloatingAppBarState extends State<_FloatingAppBar> {
}
RenderSliverFloatingPersistentHeader _headerRenderer() {
return context.ancestorRenderObjectOfType(const TypeMatcher<RenderSliverFloatingPersistentHeader>());
return context.findAncestorRenderObjectOfType<RenderSliverFloatingPersistentHeader>();
}
void _isScrollingListener() {
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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.'),
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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().',
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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;
}
}
......
......@@ -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);
}
......
......@@ -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 '
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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(
......
......@@ -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;
}
......
......@@ -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'),
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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.'
);
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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);
/// }
/// ```
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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>[
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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;
});
......
......@@ -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
......
......@@ -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);
......
......@@ -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(
......
......@@ -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));
......
......@@ -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());
......
......@@ -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];
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment