Flutter自动导入扩展文件不起作用 [英] Flutter auto importing extension file is not working
问题描述
我有一个简单的 String-Extension
,它看起来像这样:
I have a simple String-Extension
which looks like this:
extension TranslationHelper on String {
String localized() {
return AppLocalizations(Locale('de', 'DE')).translate(this);
}
}
有了这个,我可以在任何 String
上调用 .localized()
.
With this I am able to call .localized()
on any String
.
问题:Flutter或VSCode不能自动为我导入文件,也不能通过 Quick-Fix 进行建议.手动导入文件非常麻烦.这是bug还是我在这里错过了什么?
Problem: Flutter or VSCode is not auto-importing the file for me and also not suggesting it with a Quick-Fix. Importing the file manually is quite painful. Is this a bug or what am I missing here?
所有其他导入效果都很好...
All other importing works perfectly fine...
推荐答案
这是一个已知问题,目前已跟踪.
This is a known issue, and is being tracked.
作为一种解决方法,键入扩展名可以让您自动导入扩展名.例如,使用以下扩展名,键入 MyExtension
应该可以导入它.
As a workaround, typing the name of the extension should let you auto import it.
For example, with the following extension, typing MyExtension
should allow you to import it.
extension MyExtension on Object {
void doSomething() {}
}
这篇关于Flutter自动导入扩展文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!