颤动反射与可反射:需要工作示例 [英] Flutter Reflection with Reflectable: working example needed

查看:116
本文介绍了颤动反射与可反射:需要工作示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Flutter 可反射包。为了使二进制文件简短,此程序包使用代码生成。

I want to achieve reflection in a cross-platform (iOS, Android) project using Flutter and the Reflectable package. To keep the binaries short, this package uses code generation.

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

However, following the tutorial/readme of this package, I am not able to generate the needed code, in this case the file main.reflectable.dart. While I have reached the point where things work without error, code generation concludes with the statement:

[INFO] Succeeded after 88ms with 0 outputs

在下面的内容中,我尝试显示我所做的操作的可复制路径。为此,我将flutter移到了其他路径并重新安装,但没有在IntelliJ IDEA中重新安装flutter插件。

In the following I try to show a reproducible path of what I did. For that I moved flutter to a different path and reinstalled it, but didn't reinstall the flutter plugin in IntelliJ IDEA.

如何复制/我做了什么?

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内添加飞镖文件main.dart

  5. https://github.com/dart-lang/reflectable (很多都会显示为红色)

  6. 从lib目录中删除main.dart(未选中安全删除和在评论中搜索)

  7. 在测试目录中删除widet_test.dart

  8. 添加可反射的:依赖项下的pubspec.yaml

  9. 在main.dart中,单击运行,然后在随后出现的对话框中将入口点设置为/ Users /您的名字/ gitroot / PlayGround / reflectable_test_2 / entry_point / main .dart

  1. Choose SDK path: /Users/yourname/development/flutter
  2. Choose project location: ~/gitroot/PlayGround/reflectable_test_2
  3. Add directory entry_point parallel to lib directory
  4. Add dart file main.dart inside directory entry_point
  5. Get the content for main.dart from the main.dart in https://github.com/dart-lang/reflectable (a lot will be shown red)
  6. Delete main.dart from lib directory (unchecked "safe delete" and "search in comments")
  7. Delete widet_test.dart in test directory
  8. Add "reflectable: any" to pubspec.yaml under dependencies
  9. In main.dart, click run and in the upcoming dialog set the entry point to /Users/yourname/gitroot/PlayGround/reflectable_test_2/entry_point/main.dart

加载依赖项时,一些红色的摆动将消失,但不会出现在 import主体中。

When the dependencies are loaded, some of the red wiggles will go away, but not the one in "import 'main.reflectable.dart';", since this file does not exist yet.

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

III) Try to generate main.reflectable.dart with the builder on the command line:

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

请注意,本教程仅说

pub run build_runner build DIR

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

but the used line is indeed correct when used in a Flutter project. Following the readme/tutorial so far, I got the result:

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)。这将导致输出:

IV) In IntelliJ, add "build_runner: any" to dev_dependencies in pubspec.yaml. Run again on the command line (flutter packages pub run build_runner build entry_point). This results in the output:

[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个输出)。我该怎么办才能解决此问题?

To summarise, no errors, but it didn't create the file main.reflectable.dart either (0 outputs). What can I do to fix this?

推荐答案

也许唯一要做的事情就是要做

Maybe the only missing bit is to do

flutter包pub run build_runner build entry_point / main.dart

或添加 build.yaml 文件

目标:
test_reflectable:
建设者:
可反映:
generate_for:
-entry_point / main.dart

编辑:此处是一个示例存储库,可用于作为在Flutter中可反射性的非常简单的起点。

Here's an example repo which may serve as a very simplistic starting point for reflectable in Flutter.

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

Edit 2: There is a whitelist of locations where pub supports entry points ("Dart programs"), and entry_point is not on that list. Try using a directory which is present in the whitelist.

这篇关于颤动反射与可反射:需要工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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