今天当我编译flutter项目时,它显示了以下错误:
This will generate a JSON format file containing all messages that
need to be translated.
../../../.pub-cache/hosted/pub.flutter-io.cn/fish_redux-0.3.4/lib/src/redux_component/page.dart:208:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../apps/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'.
context.inheritFromWidgetOfExactType(PageProvider);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/pull_to_refresh-1.6.3/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' ('../../../apps/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);
^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/pull_to_refresh-1.6.3/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' ('../../../apps/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>());
^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/pull_to_refresh-1.6.3/lib/src/smart_refresher.dart:1003:20: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../apps/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);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/chewie-0.9.10/lib/src/chewie_player.dart:276:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../apps/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'.
context.inheritFromWidgetOfExactType(_ChewieControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/chewie_audio-1.0.0+1/lib/src/chewie_player.dart:101:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../apps/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'.
context.inheritFromWidgetOfExactType(_ChewieAudioControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我正在使用扑动主频道,我是扑动医生:
[✓] Flutter (Channel master, 1.26.0-2.0.pre.366, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-CN)
• Flutter version 1.26.0-2.0.pre.366 at /Users/dolphin/apps/flutter
• Framework revision b7f6d9bcb2 (24 hours ago), 2021-01-15 07:44:03 -0500
• Engine revision 69a7538a90
• Dart version 2.12.0 (build 2.12.0-227.0.dev)
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/dolphin/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.3, Build version 12C33
• CocoaPods version 1.10.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] IntelliJ IDEA Community Edition (version 2020.3.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] IntelliJ IDEA Ultimate Edition (version 2019.2.2)
• IntelliJ at /Users/dolphin/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (3 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.7 19H114 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.141
! Error: xiaoqiang 的 iPhone is not connected. Xcode will continue when xiaoqiang 的 iPhone is connected. (code
-13)
• No issues found!
(base)
升级到flutter 2.0.1后,再次显示此错误:
~/Documents/GitHub/cruise-open on feature/channel! ⌚ 15:01:43
$ ~/apps/flutter/bin/flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.1, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] IntelliJ IDEA Community Edition (version 2020.3.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.2.2)
[✓] VS Code (version 1.53.2)
[✓] Connected device (3 available)
! Error: xiaoqiang 的 iPhone is not connected. Xcode will continue when xiaoqiang 的 iPhone is connected. (code
-13)
• No issues found!
(base)
6条答案
按热度按时间li9yvcax1#
此错误由**inheritFromWidgetOfExactType**方法引起。
此方法已弃用。请改用**dependOnInheritedWidgetOfExactType**。
您的项目仅包含它
第一种溶液:
手动返回到版本
1.26.0-8.0
或使用以下命令:第二种溶液:
切换到测试频道
如果您还没有beta通道,则需要添加
flutter upgrade
第三种溶液:
更新您的项目
在代码中找到**inheritFromWidgetOfExactType方法,并用dependOnInheritedWidgetOfExactType**修改它。
更换示例:
**之前:**使用InheritFromWidgetOfExactType
现在使用dependOnInheritedWidgetOfExactType(推荐)
现在不再使用
Type
作为参数,该方法是泛型的。简化
<...>()
而不是(...)
该错误也可能是由您导入的程序包引起的:
**解决方案:**检查此程序包是否有新的更新
**事实上,**这个方法从flutter 1.12.1版本开始就已经过时了。但是在那之前,它是可以使用的,但是不推荐使用。从1.26.0-12.0.pre版本开始,它就不再使用了,这就解释了错误。
5tmbdcev2#
更新
随着Flutter 2的发布,从长远来看,降级SDK并不是最好的解决方案。正确的做法是检查依赖项并更新它们。您可以使用
flutter pub outdated
terminal命令突出显示可用更新-然后使用较新版本更改pubspec.yaml并尝试运行您的应用。可能会发生某些依赖项没有更新或修复Flutter SDK中的破坏性更改。在这种情况下,您将被锁定为使用旧的Flutter(直到更新依赖项或用其他软件包替换它)。原始
运行
flutter downgrade
升级后立即收到相同错误。从 Flutter 1.26.0-12.0.pre · channel dev 切换到先前版本(1.26.0-8.0.pre)使构建再次工作
这是一个快速的修正,如果你没有心情去检查
pubspec.yaml
中的依赖关系,将它们更新到新的版本(希望有null-safe的更新),而只是想从你离开的地方继续下去。最终你将不得不检查你所有的包/插件,并将它们更新/替换为 nullsafe 版本。11dmarpk3#
对我来说是因为我使用的是旧版本的依赖项。请检查pub.dev,看看是否有新版本的包!
mftmpeh84#
如果你需要在flutter 1.26中运行provider,你应该运行:Flutter降级。
如果你需要在flutter 2.0.0 +中运行provider,你应该修改:
pubspec.yaml
提供程序:^2.0.1到^5.0.0
main.dart
更改创建的构建器
第一个月
fzsnzjdm5#
这种情况经常发生在开发和主通道上,flutter认为最稳定的主通道是Beta通道
Flutter build release channels
我们将在月初,通常是第一个星期一,从master分支到一个新的beta版本。这将包括一个Dart分支,引擎分支和框架分支。这个分支将在接下来的几周内“稳定”,这意味着我们将接受cherrypick对高影响问题的请求。当我们接近月底和下一个beta分支时,我们可能会减少我们愿意做的樱桃的数量。2一个季度一次,测试分支将继续生存,成为下一个稳定的分支,如下所述。
koaltpgm6#
使用低于4.0.0的
provider
版本时会出现此问题。您可以通过打开
pubspec.yaml
文件并将提供程序版本更改为4.0.0或更高版本来解决此问题。