Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 错误:方法';继承自WidgeToFexactType';isn';t为类定义';BuildContext';_Flutter - Fatal编程技术网

Flutter 错误:方法';继承自WidgeToFexactType';isn';t为类定义';BuildContext';

Flutter 错误:方法';继承自WidgeToFexactType';isn';t为类定义';BuildContext';,flutter,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 'inheritFromWi

今天,当我编译颤振项目时,它显示了以下错误:

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)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
这将生成一个JSON格式的文件,其中包含
需要翻译。
../../../...pub cache/hosted/pub.flatter io.cn/fish_redux-0.3.4/lib/src/redux_component/page.dart:208:17:错误:未为类“BuildContext”定义方法“inheritFromWidgetOfExactType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
请尝试将名称更正为现有方法的名称,或定义名为“inheritFromWidgetOfExactType”的方法。
继承自WidgeToFexactType(页面提供程序);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../...pub cache/hosted/pub.flatter io.cn/pull_to_refresh-1.6.3/lib/src/smart_refresh.dart:273:21:错误:未为类“BuildContext”定义方法“ancestorWidgetOfExactType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
请尝试将名称更正为现有方法的名称,或定义名为“ancestorWidgetOfExactType”的方法。
返回上下文?.ancestorWidgetOfExactType(SmartRefresher);
^^^^^^^^^^^^^^^^^^^^^^^^^
../../../...pub cache/hosted/pub.flatter io.cn/pull_to_refresh-1.6.3/lib/src/smart_refresh.dart:277:21:错误:未为类“BuildContext”定义方法“ancestorStateOfType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
尝试将名称更正为现有方法的名称,或定义名为“ancestorStateOfType”的方法。
返回上下文?.ancestorStateOfType(TypeMatcher());
^^^^^^^^^^^^^^^^^^^
../../../...pub cache/hosted/pub.flatter io.cn/pull_to_refresh-1.6.3/lib/src/smart_refresh.dart:1003:20:错误:未为类“BuildContext”定义方法“inheritFromWidgetOfExactType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
请尝试将名称更正为现有方法的名称,或定义名为“inheritFromWidgetOfExactType”的方法。
返回context.inheritFromWidgetOfExactType(刷新配置);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../...pub cache/hosted/pub.flatter io.cn/chuwie-0.9.10/lib/src/chuwie_player.dart:276:17:错误:未为类“BuildContext”定义方法“inheritFromWidgetOfExactType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
请尝试将名称更正为现有方法的名称,或定义名为“inheritFromWidgetOfExactType”的方法。
context.inheritFromWidgetOfExactType(\u chuvieControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../...pub cache/hosted/pub.flatter io.cn/chuvie_audio-1.0.0+1/lib/src/chuvie_player.dart:101:17:错误:未为类“BuildContext”定义方法“inheritFromWidgetOfExactType”。
-“BuildContext”来自“package:flatter/src/widgets/framework.dart”(“../../../apps/flatter/packages/flatter/lib/src/widgets/framework.dart”)。
请尝试将名称更正为现有方法的名称,或定义名为“inheritFromWidgetOfExactType”的方法。
context.inheritFromWidgetOfExactType(\u chuvieAudioControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我正在使用颤振主通道,这是颤振医生:

[✓] 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:
      Upd!

With Flutter 2 release downgrading SDK is not the best workaround in longer term. The right thing to do is going through dependencies and updating them, you can use
flutter pub outdated
terminal command to highlight available updates - then change pubspec.yaml with newer versions and try running your app. It might happen that some dependencies won't have the updates or fixes for the breaking changes in Flutter SDK. In this case you'll be locked into using older Flutter (until the dependency is updated or you replace it with some other package).

Orig

Run
flutter downgrade

Received same error right after upgrading. Switching from Flutter 1.26.0-12.0.pre • channel dev to the previous verion (1.26.0-8.0.pre) made the build work again

This is a quickfix in case you are not in a mood to go through dependencies in
pubspec.yaml
updating them to newer ones (hoping there're updates to null-safety) but just want to carry on from the place you left. Eventualy you'll have to go through all your packages/plugins and update/replace them with nullsafe versions.

For me was because I was using an old version of my dependencies. Check pub.dev to see if has a new version of your packages!

This often happened when working with Dev and master channels, the best monthly picks of master that flutter consider more stable is channel Beta

flutter channel beta
[✓] 颤振(通道主控,1.26.0-2.0.366之前,Mac OS X 10.15.7 19H114 darwin-x64上,中国语言环境)
•颤振版本1.26.0-2.0.pre.366 at/Users/dolphin/apps/颤振
•框架版本b7f6d9bcb2(24小时前),2021-01-15 07:44:03-0500
•发动机版本69a7538a90
•Dart版本2.12.0(版本2.12.0-227.0.dev)
•发布下载镜像https://pub.flutter-io.cn
•颤振下载镜像https://storage.flutter-io.cn
[✓] Android工具链-为Android设备开发(Android SDK版本30.0.2)
•Android SDK位于/Users/dolphin/Library/Android/SDK
•平台android-30,构建工具30.0.2
•Java二进制地址:/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/Java
•Java版本OpenJDK运行时环境(build 1.8.0_242-release-1644-b3-6915495)
•接受所有Android许可证。
[✓] Xcode-为iOS和macOS开发
•Xcode at/Applications/Xcode.app/Contents/Developer
•Xcode 12.3,构建版本12C33
•CocoaPods 1.10.0版
[✓] Chrome-为web开发
•Chrome at/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio(4.1版)
•Android Studio位于/Applications/Android Studio.app/Contents
•颤振插件可从以下位置安装:
Upd!

从长远来看,使用Flatter 2版本降级SDK并不是最好的解决办法。正确的做法是检查依赖项并更新它们,您可以使用
flatter pub过时的
terminal命令突出显示可用的更新,然后用更新的版本更改pubspec.yaml,并尝试运行您的应用程序。可能会出现以下情况:依赖项不会更新或修复Flatter SDK中的破坏性更改。在这种情况下,您将被锁定使用较旧的Flatter(直到更新依赖项或用其他包替换它)

原版

运行
颤振降坡

升级后立即收到相同的错误。从Flatter 1.26.0-12.0.pre•channel dev切换到以前的verion(1.26.0-8.0.pre)使构建再次工作

这是一个快速修复的情况下,你没有心情去通过depende
flutter downgrade
flutter channel beta
static Name of(BuildContext context) {
  return context.inheritFromWidgetOfExactType(Name);  //before
}
static Name of(BuildContext context) {
  return context.dependOnInheritedWidgetOfExactType<Name>();  //after
}