英文:
Flutter Error Undefined class 'RenderContext'
问题
我遇到了运行以前与另一个人一起工作正常的Flutter项目的问题。具体来说,我遇到了与RenderContext
类相关的错误。我看到的错误消息是:'未定义类'RenderContext'(未定义类位于[文件路径]:[行号])。'
我正在使用IntelliJ作为这个项目的环境,这是我第一次在IntelliJ中使用Flutter。我已经尝试使用Android Studio来解决这个问题。
然而,我仍然遇到与RenderContext相关的相同错误消息。我怀疑在IntelliJ中可能有一些配置或设置步骤我可能遗漏了。
你能否提供如何解决这个问题并在IntelliJ中再次运行我的项目的任何建议或指导?谢谢你的帮助!
错误
运行Gradle任务'assembleDebug'...
- ../../../../AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-
2.2.2/lib/src/html/dom/element_subclasses.dart:2752:30: 错误:无法将参数类型'String?'分配给参数类型'Object',因为'String?'是可空的而'Object'不是。
'Object'来自'dart:core'。
final parsed = css.parse(text);
^
- lib/view/screens/location/widget/web_landing_page.dart:268:51: 错误:'RenderContext'不是一个类型。
onLinkTap: (String url, RenderContext context, Map<String, String> attributes, element) {
^^^^^^^^^^^^^
- lib/view/screens/location/widget/web_landing_page.dart:268:38: 错误:参数类型'Null Function(String, invalid-type, Map<String, String>,
dynamic)'无法赋给参数类型'void Function(String, Map<String, String>, Element)'。
'Map'来自'dart:core'。
'Element'来自'package:html/dom.dart'('../../../../AppData/Local/Pub/Cache/hosted/pub.dev/html-0.15.4/lib/dom.dart')。
onLinkTap: (String url, RenderContext context, Map<String, String> attributes, element) {
^
- lib/view/screens/html/html_viewer_screen.dart:111:57: 错误:'RenderContext'不是一个类型。
onLinkTap: (String url, RenderContext context,
^^^^^^^^^^^^^
- lib/view/screens/html/html_viewer_screen.dart:108:31: 错误:方法'SelectableHtml'对于类'_HtmlViewerScreenState'未定义。
-'_HtmlViewerScreenState'来自'package:alqalaf/view/screens/html/html_viewer_screen.dart'('lib/view/screens/html/html_viewer_screen.dart')。
请尝试将名称更正为现有方法的名称,或定义名为'SelectableHtml'的方法。
: SelectableHtml(
^^^^^^^^^^^^^^
目标kernel_snapshot失败:异常
失败:构建失败,发生异常。
英文:
I am having trouble running a Flutter project that was previously working fine with a different person. Specifically, I am encountering an error related to the RenderContext
class. The error message I am seeing is: 'Undefined class 'RenderContext' (undefined_class at [path to my file]:
I am using IntelliJ as my environment for this project, and this is my first time using IntelliJ with Flutter. I have tried to use Android Studio to solve this problem.
However, I am still encountering the same error message related to RenderContext. I suspect that there may be a configuration or setup step in IntelliJ that I may have missed.
Can you please offer any suggestions or guidance on how to resolve this issue and get my project running again in IntelliJ? Thank you for your assistance!
The Error
Running Gradle task 'assembleDebug'...
- ../../../../AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-
2.2.2/lib/src/html/dom/element_subclasses.dart:2752:30: Error: The argument type
'String?' can't be assigned to the parameter type 'Object' because 'String?' is nullable and 'Object' isn't.
'Object' is from 'dart:core'.
final parsed = css.parse(text);
^
- lib/view/screens/location/widget/web_landing_page.dart:268:51: Error: 'RenderContext' isn't a type.
onLinkTap: (String url, RenderContext context, Map<String, String> attributes, element) {
^^^^^^^^^^^^^
- lib/view/screens/location/widget/web_landing_page.dart:268:38: Error: The argument type 'Null Function(String, invalid-type, Map<String, String>,
dynamic)' can't be assigned to the parameter type 'void Function(String, Map<String, String>, Element)'.
'Map' is from 'dart:core'.
'Element' is from 'package:html/dom.dart' ('../../../../AppData/Local/Pub/Cache/hosted/pub.dev/html-0.15.4/lib/dom.dart').
onLinkTap: (String url, RenderContext context, Map<String, String> attributes, element) {
^
- lib/view/screens/html/html_viewer_screen.dart:111:57: Error: 'RenderContext' isn't a type.
onLinkTap: (String url, RenderContext context,
^^^^^^^^^^^^^
- lib/view/screens/html/html_viewer_screen.dart:108:31: Error: The method 'SelectableHtml' isn't defined for the class '_HtmlViewerScreenState'.
-'_HtmlViewerScreenState' is from 'package:alqalaf/view/screens/html/html_viewer_screen.dart' ('lib/view/screens/html/html_viewer_screen.dart').
Try correcting the name to the name of an existing method, or defining a method named 'SelectableHtml'.
: SelectableHtml(
^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
答案1
得分: 0
由于html包的版本问题,新版本已删除RenderContext,您可以尝试在pubspec.yaml文件中删除^符号。
示例:
flutter_html: ^3.0.0-alpha.6
更改为 flutter_html: 3.0.0-alpha.6
英文:
Probably because html package version, the newer version has removed RenderContext, you can try removing the ^ symbol in the pubspec.yaml file.
example:
flutter_html: ^3.0.0-alpha.6 to flutter_html: 3.0.0-alpha.6
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论