从 flutter 1.9 开始,flutter_web 被合并到 flutter 中。我尝试在 Chrome 浏览器中运行初始 flutter 应用程序,但失败了。操作系统是ubuntu 19.04
我成功使用的命令: 颤振升级
flutter 创建 test_1_9
cd test_1_9
颤抖奔跑
命令不起作用:
flutter run -d chrome
=> 未找到名称或 ID 与“chrome”匹配的设备
我尝试使用 google-chrome 作为设备名称,结果相同
[✓] Flutter (Channel master, v1.10.2-pre.38, on Linux, locale fr_FR.UTF-8)
• Flutter version 1.10.2-pre.38 at /home/rbarbe/programes/flutter
• Framework revision e6ae95c4ce (il y a 18 heures), 2019-09-11 07:46:57 -0700
• Engine revision 7ea9884ab0
• Dart version 2.5.0 (build 2.5.0-dev.4.0 be66176534)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /home/rbarbe/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /home/rbarbe/programes/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[✓] Android Studio (version 3.3)
• Android Studio at /home/rbarbe/programes/android-studio
• Flutter plugin version 33.3.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[✓] IntelliJ IDEA Community Edition (version 2019.1)
• IntelliJ at /home/rbarbe/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/191.6183.87
• Flutter plugin version 35.2.2
• Dart plugin version 191.6183.88
[✓] IntelliJ IDEA Community Edition (version 2019.2)
• IntelliJ at /home/rbarbe/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/192.6603.28
• Flutter plugin version 39.0.5
• Dart plugin version 192.6603.23
[✓] VS Code (version 1.38.0)
• VS Code at /usr/share/code
• Flutter extension version 3.4.1
[✓] Connected device (1 available)
• CLT L29 • WCR0218315003400 • android-arm64 • Android 9 (API 28)
• No issues found!
对于这些在
chrome
之后仍然无法检测到flutter config --enable-web
的人,你应该检查你的flutter是否在适当的分支,要列出所有分支,请使用:
颤振通道
输出可能如下所示:
Flutter channels:
beta
dev
master
* stable
带有星号前缀的项目表示您所在的分支。要切换到主分支,请尝试:
颤振通道大师
之后,您的
flutter doctor
可以列出 chrome
设备。
https://flutter.dev/docs/get-started/web
$ flutter channel master
$ flutter upgrade
$ flutter config --enable-web
$ flutter devices //downloads sky_engine and sdk tools then shows a list of devices including chrome
$ flutter create test_app
$ flutter run -d chrome //local host will run chrome
flutter run -d chrome --web-renderer html
就我而言 - flutter doctor 给了我以下输出
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
在 arch 上,二进制文件称为 google-chrome-stable 和/或 google-chrome-unstable
export CHROME_EXECUTABLE=/usr/bin/google-chrome-stable
这就是让它工作所需的一切。
您需要运行一个 Web 服务器,然后可以在端口(大概是 8080)上使用。如果一切设置正确,您可以:
webdev serve
否则尝试:
flutter packages pub global run webdev serve
还要确保从 master 分支而不是稳定分支升级 flutter
您需要 cd 到 flutter 安装工作区,然后运行:
git checkout master
对于 Ubuntu,请通过运行确保您位于主通道上
flutter通道大师
然后运行
颤振升级
允许 HTML Web 渲染运行
flutter run -d chrome --web-renderer html
将 chrome 添加到用户变量对我有用,我将 chrome 移动到另一个驱动器,但 flutter 没有识别它。
系统属性>环境变量>在用户上,创建新的然后添加:
变量名称:CHROME_EXECUTABLE
变量值:D:\Program Files\Google\Chrome\Applicatio