无法运行 Dart 2 with / Angular for web 以及 Flutter for mobile 项目 - 计划共享代码

Posted

技术标签:

【中文标题】无法运行 Dart 2 with / Angular for web 以及 Flutter for mobile 项目 - 计划共享代码【英文标题】:Unable to run Dart2 w/ Angular for web along side Flutter for mobile project - plan to share code 【发布时间】:2018-09-29 03:26:57 【问题描述】:

我在移动应用上使用 Flutter 取得了不错的进展。目前使用:

[✓] Flutter(Channel master,v0.3.1-pre.13,Mac OS X 10.13.4 17E199,locale en-US)

• Flutter version 0.3.1-pre.13 at /Users/golftocs/phpstormProjects/flutter

• Framework revision 85be28d36b (32 hours ago), 2018-04-16 14:02:07 -0700

• Engine revision 76cb311d9c

• Dart version 2.0.0-dev.47.0.flutter-f76dad0adc

[✓] android 工具链 - 为 Android 设备开发 (Android SDK 27.0.1)

• Android SDK at /Users/golftocs/Library/Android/sdk

• Android NDK location not configured (optional; useful for native profiling support)

• Platform android-27, build-tools 27.0.1

• ANDROID_HOME = /Users/golftocs/Library/Android/sdk

• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java

• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

• All Android licenses accepted.

[✓] ios 工具链 - 为 iOS 设备开发 (Xcode 9.3)

• Xcode at /Applications/Xcode.app/Contents/Developer

• Xcode 9.3, Build version 9E145

• ios-deploy 1.9.2

• CocoaPods version 1.5.0

[✓] Android Studio(版本 3.1)

• Android Studio at /Applications/Android Studio.app/Contents

• Flutter plugin version 23.1.2

• Dart plugin version 173.4700

• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] 连接的设备

! No devices available

现在我想开始一个项目,使用这个 Flutter 移动设备设置并与 Dart2/Angular 网络应用程序共享代码。我无法让 Web 应用程序成功运行。我已经克隆了 https://github.com/angular-examples/toh-5 并基于运行 'pub get' 返回:

Overriding the upper bound Dart SDK constraint to <=2.0.0- 
edge.0d5cf900b021bf5c9fa593ffa12b15bcd1cc5fe0 for the following packages:



archive, args, barback, bazel_worker, boolean_selector, build_barback, 
build_config, build_modules, charcode, cli_util, code_transformers, 
convert, crypto, csslib, dart_style, fixnum, front_end, glob, graphs, 
html, http, http_multi_server, http_parser, intl, io, isolate, js, 
json_annotation, kernel, logging, matcher, meta, multi_server_socket, 
node_preamble, package_config, package_resolver, path, plugin, pool, 
protobuf, pub_semver, quiver, quiver_hashcode, shelf, 
shelf_packages_handler, shelf_static, shelf_web_socket, 
source_map_stack_trace, source_maps, source_span, stack_trace, 
stream_channel, string_scanner, term_glyph, test, tuple, typed_data, yaml

然后,当我从终端运行“pub run build_runner serve”时,我得到:

[INFO] Generating build script completed, took 446ms

[INFO] Setting up file watchers completed, took 25ms

[INFO] Waiting for all file watchers to be ready completed, took 199ms

[INFO] Building new asset graph completed, took 921ms

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

[SEVERE] build_web_compilers|ddc on package:angular_router/src/url.module:


ProcessException: No such file or directory

  Command: /Users/golftocs/PhpstormProjects/flutter/bin/cache/dart-sdk/bin/dartdevc --persistent_worker

[WARNING] build_web_compilers|entrypoint on web/main.dart:

Unable to read angular_router|lib/src/url.ddc.js, check your console or         the `.dart_tool/build/generated/angular_router/lib/src/url.ddc.js.errors` log file.

[SEVERE] build_web_compilers|ddc on     package:angular_router/src/location/platform_location.module:


ProcessException: No such file or directory

Command: /Users/golftocs/PhpstormProjects/flutter/bin/cache/dart-sdk/bin/dartdevc --persistent_worker

[WARNING] build_web_compilers|entrypoint on web/main.dart:

Unable to read angular_router|lib/src/location/platform_location.ddc.js, check your console or the `.dart_tool/build/generated/angular_router/lib/src/location/platform_location.ddc.js.errors` log file.

...

此外,我正在使用 WebStorm,实际上是 PHPStorm,并且指向“获取依赖项、升级...”的 Pub 操作链接不起作用。我只能从终端执行。

我的愿望是: 1) 在移动和网络之间共享代码类似于https://github.com/apptreesoftware/letsvote/blob/master/README.md 2) 使用 Angular5.0.0-alpha 和当前 Flutter 主通道运行最新的 Dart2 3) WebStorm IDE 可以与组合项目中的任何一个无缝协作

谢谢。

【问题讨论】:

【参考方案1】:
shared_code
  |- flutter_project
  |- angular_project

flutter_projectangular_projectshared-code 中都具有 shared-code 作为 pubspec.yaml 的依赖项

dependencies:
  shared_code:
    path: ../shared_code

假设目录结构类似于

my_project/shared_code
my_project/flutter_project
my_project/angular_project

shared_code 中的代码不得以任何方式依赖于dart:ioflutter:ui,否则它将无法与flutter_projectangular_project 一起使用

如果您想在 IntelliJ 中的同一窗口中同时打开所有 3 个,将它们作为模块添加到单个项目中对我有用。 当我做Angular项目时,我需要将Dart插件中的Dart SDK切换到Dart SDK,当我处理Flutter项目时,我需要切换到Flutter Dart SDK,否则运行应用程序和测试不起作用。

您还可以在其自己的 IntelliJ 窗口中打开每个项目,该窗口单独保留每个窗口的设置,无需根据您当前正在工作的代码进行切换。

【讨论】:

非常感谢。我试图用 Flutter Dart SDK 为 Angular 端运行 Dart。单独下载 Dart SDK,在此处指向 Dart SDK Path,然后重新启动我的 IDE 即可!我对共享代码的计划将是纯 Dart 并包括服务器接口和尽可能的业务逻辑。我也感谢您对项目架构的指导。干杯! 很高兴听到。 Flutter SDK 是自定义的,不包含dart:html,这也是你需要 Dart SDK 的原因。很高兴听到你能成功。

以上是关于无法运行 Dart 2 with / Angular for web 以及 Flutter for mobile 项目 - 计划共享代码的主要内容,如果未能解决你的问题,请参考以下文章

Dart pub 全局运行无法解析脚本名称

Dart 中的 extends / with / implements

我升级了 Flutter(和 Dart),现在我无法让 WebApps 工作

在 VSCode 中启用 Dart DevTools 时出现错误 - Dart DevTools exited with code 65

Flutter with Firebase Google 登录:断言失败 network_image_io.dart

Dart 虚拟机运行原理