我正在尝试 inject.dart在我的副项目中,但未能成功编译我的应用程序。
如果有帮助的话可以看看我的项目here .
由于目前没有正式版本,我已将 inject
和 inject_generator
包复制到我的项目中。然后,我运行:
pub run build_runner build
(或flutter packages pub run build_runner build
)
我看到生成的文件全部在 .dart_tools/build/generated
中成功创建,但是我在 lib/
中的文件无法引用生成的文件。因此,每次尝试运行我的应用程序时,我都会收到编译错误。
有人知道我做错了什么(或可能做错了什么)吗?我是否应该能够引用此文件夹中的文件?
最佳答案
您也许可以通过指定 build_to: source
来获得所需的结果,如本示例所示
https://github.com/dart-lang/build/blob/10667edc1ed4f3e5d15fcfd2d0a447113f89e982/example/build.yaml
builders:
copyBuilder:
import: "package:example/builder.dart"
builder_factories: ["copyBuilder"]
build_extensions: {".txt": [".txt.copy"]}
build_to: source
auto_apply: root_package
- build_to: Optional. The location that generated assets should be output to. The possibilities are:
"source"
: Outputs go to the source tree next to their primary inputs."cache"
: Outputs go to a hidden build cache and won't be published. The default is "cache". If a Builder specifies that it outputs to "source" it will never run on any package other than the root - but does not necessarily need to use the "root_package" value for "auto_apply". If it would otherwise run on a non-root package it will be filtered out.
关于dart - 如何在flutter项目中引用.dart_tools中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49837314/