flutter - 如何修复错误:没有为类“BuildContext”定义方法“ancestorWidgetOfExactType”
问题描述
为了解决这个问题,我进行了搜索,但我发现没有为类“BuildContext”问题的解决方案定义“inheritFromWidgetOfExactType”的解决方案。我找不到任何解决这个问题的方法 'ancestorWidgetOfExactType' 方法没有为类'BuildContext' 定义。
升级颤振 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
这是我的颤振医生
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)
解决方案
在 pubspec.yaml 中尝试:
pull_to_refresh: 1.6.4-nullsafety.0
推荐阅读
- r - 如何将三角形添加到 R 中的 ggplot2 颜色条以指示超出范围的值?
- javascript - 为什么此代码更改字符串但又恢复到原始状态
- odoo - 如何禁用其他用户的更改密码选项?
- typescript - Typescript assumes the property type to be T | Properties["key"] instead of just T
- c++ - 就地创建和填充数组
- antlr4 - 如何解析无法转换为解析器规则的长词法规则的标记?
- hybris - 基于从 FlexQuery 获得的 PK 导入 Hybris Impex
- python-3.x - Python,将字典转换为逗号分隔值
- model - 如何使用 OR-Tools for python 描述目标大于零
- autodesk-forge - 模型衍生 API 对象 ID 与 PropertyDatabase 对象 ID 不匹配