Flutter扩展方法不起作用,它表示“未定义的类".并且“需要扩展方法语言功能"; [英] Flutter extension-methods not working, it says "undefined class" and "requires the extension-methods language feature"

查看:923
本文介绍了Flutter扩展方法不起作用,它表示“未定义的类".并且“需要扩展方法语言功能";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 dlblack.dev 逐步构建我的个人网站,并且我试图为其增添趣味一点点.例如,从计算机(而不是平板电脑或电话,因为它们没有鼠标指针),如果将鼠标悬停在任何可点击的项目上,它不会更改鼠标指针以指示它是可点击的,以及可点击的对象完全没有改变.我决定遵循此FilledStacks教程 ,但没有提及解决此问题的任何内容.

I'm slowly building my personal website over at dlblack.dev, and I'm trying to spice it up a little bit. For example, from a computer (rather than a tablet or phone since they don't have mouse pointers), if you hover over any of the clickable items, it doesn't change your mouse pointer to indicate it's clickable, and the clickable object doesn't change at all. I've decided to follow this FilledStacks tutorial, but it doesn't mention anything about fixing this problem.

基本上,发生的事情是当我通过教程视频(他编写骨架扩展类)大约2.5分钟并尝试复制该视频时,VS Code重命名了除名称之外的几乎整个类声明.我在写的东西和他在2:26的屏幕上写的完全一样,这是我的代码:

Essentially what's happening is when I get ~2.5 mins through the tutorial video (where he writes the skeleton extension class) and try to duplicate it, VS Code redlines almost the entire class declaration aside from the name. What I'm writing is the exact same thing as what he has on screen at 2:26, and here's my code:

import 'package:flutter/material.dart';
import 'dart:html' as html;

extension HoverExtension on Widget{
  
}

扩展名",在…上"和窗口小部件";当我这样做时,都被涂上了红线.当我将鼠标悬停在扩展名"上时,它表示以下内容:

"extension", "on", and "Widget" are all redlined when I do this. When I hover over "extension", it says the following:

Undefined class 'extension'.
Try changing the name to the name of an existing class, or creating a class with the name 'extension'. dartundefined_class
This requires the 'extension-methods' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 2.6 or higher, and running 'pub get'. dart(experiment_not_enabled)

我要做的第一件事是将pubspec.yaml文件中的最低SDK约束更改为2.6.0.然后我将其更改为2.7.0,因为许多在线用户表示扩展是在Dart 2.7中发布的.我已经完成了很多关于该主题的搜索,但似乎没有人遇到与我相同的问题:我没有analysis_options.yaml文件.我创建了一个,并将 only 放在其内容中:

The first thing I did was change my minimum SDK constraint to 2.6.0 in my pubspec.yaml file. I then changed it to 2.7.0 because a lot of people online say extensions were released in Dart 2.7. I've done a lot of Googling on the subject but no one seems to have the same problem as me: I have no analysis_options.yaml file. I created one, and put only this in its contents:

include:

analyzer:
  enable-experiment:
    - extension-methods

linter:

从理论上讲,我相信一旦从根文件夹中的命令行运行flutter pub get,该问题就可以解决.没有.我不知道怎么了有什么建议吗?

In theory, I believe that should fix my problem once I run flutter pub get from the command line in my root folder; it doesn't. I have no idea what's wrong. Any suggestions?

推荐答案

要使pubspec.yaml和analysis_options.yaml发生更改,您必须重新启动Dart Analysis Server.在VSCode中,这就像Ctrl + Shift + P->一样简单.重新加载窗口.

For the changes in pubspec.yaml and analysis_options.yaml to take place, you have to restart the Dart Analysis Server. In VSCode, that's as simple as Ctrl+Shift+P -> Reload Window.

这篇关于Flutter扩展方法不起作用,它表示“未定义的类".并且“需要扩展方法语言功能";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆