我是靠谱客的博主 机灵未来,最近开发中收集的这篇文章主要介绍flutter项目提示 Superclass has no method named ‘inheritFromElement‘等错误解决,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

完整错误信息如下:

/D:/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/delegate_widget.dart:194:18: Error: Superclass has no method named 'inheritFromElement'.
return super.inheritFromElement(ancestor, aspect: aspect);
^^^^^^^^^^^^^^^^^^
/D:/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/D:/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(type) as InheritedProvider<T>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/D:/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/D:/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
: context.ancestorInheritedElementForWidgetOfExactType(type)?.widget
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'D:flutterpackagesflutter_toolsgradleflutter.gradle' line: 991
* What went wrong:
Execution failed for task ':flutter:compileFlutterBuildDebug'.
> Process 'command 'D:flutterbinflutter.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 7s
Gradle task assembleAarDebug failed with exit code 0.
  • flutter版本:2.0.4
  • provider版本:3.2.0

问题原因

provider该版本中使用了flutter2.x.x不兼容的方法,讲provider升级到新版(如provider 5.0.0)即可。

解决办法

编辑项目根目录下的【pubspec.yaml】文件,把【dependencies】下的【provider】版本改为5.0.0,以我的为例:

dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^5.0.0

结束!

最后

以上就是机灵未来为你收集整理的flutter项目提示 Superclass has no method named ‘inheritFromElement‘等错误解决的全部内容,希望文章能够帮你解决flutter项目提示 Superclass has no method named ‘inheritFromElement‘等错误解决所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部