Flutter 如何修复错误:方法&x27;ancestorWidgetOfExactType';isn';t为类定义';BuildContext';

Flutter 如何修复错误:方法&x27;ancestorWidgetOfExactType';isn';t为类定义';BuildContext';,flutter,Flutter,为了解决此问题,我搜索了,但发现没有为类“BuildContext”问题的解决方案定义“inheritFromWidgetOfExactType”的解决方案。我找不到此问题的任何解决方案。未为类“BuildContext”定义方法“ancestorWidgetOfExactType” 在升级颤振2.0.2之后,我在编译我的项目后遇到了这些错误 /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.2/lib/

为了解决此问题,我搜索了,但发现没有为类“BuildContext”问题的解决方案定义“inheritFromWidgetOfExactType”的解决方案。我找不到此问题的任何解决方案。未为类“BuildContext”定义方法“ancestorWidgetOfExactType”

在升级颤振2.0.2之后,我在编译我的项目后遇到了这些错误

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.2/lib/src/smart_refresher.dart:273:21: Error: The method 'ancestorWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').

Try correcting the name to the name of an existing method, or defining a method named 'ancestorWidgetOfExactType'.
    return context?.ancestorWidgetOfExactType(SmartRefresher);
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.2/lib/src/smart_refresher.dart:277:21: Error: The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorStateOfType'.
    return context?.ancestorStateOfType(TypeMatcher<SmartRefresherState>());
                    ^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.2/lib/src/smart_refresher.dart:988:20: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
    return context.inheritFromWidgetOfExactType(RefreshConfiguration);
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_staggered_animations-0.1.2/lib/src/animation_configuration.dart:161:20: Error: The method 'ancestorWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorWidgetOfExactType'.
    return context.ancestorWidgetOfExactType(AnimationConfiguration)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_staggered_animations-0.1.2/lib/src/animation_limiter.dart:75:20: Error: The method 'ancestorWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').

Try correcting the name to the name of an existing method, or defining a method named 'ancestorWidgetOfExactType'.
    return context.ancestorWidgetOfExactType(_AnimationLimiterProvider)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_neumorphic-3.0.2/lib/src/widget/app_bar.dart:147:57: Error: No named parameter with the name 'nullOk'.
    final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
                                                        ^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart:1944:24: Context: Found this candidate, but the arguments don't match.
  static ScaffoldState of(BuildContext context) {
                       ^^
2

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5m 31s
Exception: Gradle task assembleDebug failed with exit code 1
在pubspec.yaml中尝试:

拉_到_刷新:1.6.4-nullsafety.0

执行
flatter pub clean
并重新运行。
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19042.867], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.54.2)
[√] Connected device (2 available)