小编典典

颤动反射与可反射:需要工作示例

flutter

我想使用FlutterReflectable
package
在跨平台(iOS,Android)项目中实现反射。为了使二进制文件简短,此程序包使用代码生成。

但是,按照此软件包的教程/自述文件,我无法生成所需的代码,在这种情况下,文件为main.reflectable.dart。在达到一切正常而没有错误的地步时,代码生成以以下语句结束:

[INFO] Succeeded after 88ms with 0 outputs

在下面的内容中,我试图显示出我所做的事情的可复制路径。为此,我将flutter移到了另一个路径并重新安装了它,但是没有在IntelliJ
IDEA中重新安装flutter插件。

如何复制/我做了什么?

I)像往常一样为Mac 安装Flutter 。在命令行上:

cd ~/development 
git clone -b beta https://github.com/flutter/flutter.git 
export PATH=/Users/yourname/development/flutter/bin:$PATH 
flutter doctor

II)在IntelliJ IDEA中 创建一个新的Flutter项目

  1. 选择SDK路径:/ Users /您的姓名/开发/ flutter
  2. 选择项目位置:〜/ gitroot / PlayGround / reflectable_test_2
  3. 添加与lib目录平行的目录entry_point
  4. 在目录entry_point内添加dart文件main.dart
  5. https://github.com/dart-lang/reflectable中的main.dart获取main.dart的内容(很多都会显示为红色)
  6. 从lib目录中删除main.dart(未选中“安全删除”和“在注释中搜索”)
  7. 删除测试目录中的widet_test.dart
  8. 在依赖项下将“ reflectable:any”添加到pubspec.yaml
  9. 在main.dart中,单击运行,然后在随后出现的对话框中将入口点设置为/ Users /您的名称/gitroot/PlayGround/reflectable_test_2/entry_point/main.dart

加载依赖项时,一些红色摆动将消失,但“ import’main.reflectable.dart’;”中的红色摆动不会消失,因为该文件尚不存在。

III) 尝试 在命令行上使用 生成生成main.reflectable.dart

cd /Users/yourname/gitroot/PlayGround/reflectable_test_2/
flutter packages pub run build_runner build entry_point

请注意,本教程只说最后一行,而不是最后一行

pub run build_runner build DIR

但是在Flutter项目中使用的线确实是正确的。按照到目前为止的自述文件/教程,我得到了结果:

Package "build_runner" is not an immediate dependency.
Cannot run executables in transitive dependencies.
pub finished with exit code 65

IV)在IntelliJ中,将“
build_runner:any”添加到pubspec.yaml中的dev_dependencies。在命令行上再次运行(flutter包pub run
build_runner build entry_point)。结果为输出:

[INFO] Generating build script...
[INFO] Generating build script completed, took 506ms

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 776ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 3ms

[INFO] Running build...
[INFO] Running build completed, took 7ms

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 69ms

[INFO] Succeeded after 88ms with 0 outputs

总而言之,没有错误,但是也没有创建文件main.reflectable.dart(0个输出)。我该怎么做才能解决此问题?


阅读 578

收藏
2020-08-13

共1个答案

小编典典

也许唯一缺少的是

flutter packages pub run build_runner build entry_point/main.dart

或按照以下方式添加build.yaml文件

targets: test_reflectable: builders: reflectable: generate_for: - entry_point/main.dart

编辑:是一个 示例存储库
,它可以作为Flutter中可反射的非常简单的起点。

编辑2:有一个支持入口点的位置白名单pub(“飞镖程序”),entry_point不在该列表中。尝试使用白名单中存在的目录。

2020-08-13