dart - 如何在flutter项目中引用.dart_tools中的文件?

标签 dart flutter

我正在尝试 inject.dart在我的副项目中,但未能成功编译我的应用程序。

如果有帮助的话可以看看我的项目here .

由于目前没有正式版本,我已将 injectinject_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

https://github.com/dart-lang/build/blob/dff811be8b99e0ac7b15a8c7b9ad7bd2b5027a1d/build_config/README.md中有一些解释

  • 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/

相关文章:

dart - 在 polymer.dart 中更新动态计算的属性

flutter - 使用共享首选项列表抖动保存和检索通知

postgresql - 如何从 dart 中的 conn.query 获取数据

html - 使用 Dart 编辑 CSS

dart - 如何在 Dart 中发送大的 POST 数据

菜单 slider 中的 flutter 子项

flutter 驱动: How to check device orientation?

dart - 什么是boot.js(Dart)

android - 在 headless (headless)模式下获取本地化字符串

dart - 为什么颜色没有变化?