我用的是Mac 其它電腦類似
1技肩、打開終端
cd 到項目路徑下
然后終端 輸入
flutter packages pub global activate webdev
提示下面內(nèi)容俗孝,警告去path環(huán)境變量文件里
Downloading source_maps 0.10.9...
Downloading collection 1.14.13...
Downloading matcher 0.12.9...
Downloading stack_trace 1.9.6...
Precompiling executables...
Precompiled webdev:webdev.
Installed executable webdev.
Warning: Pub installs executables into /opt/flutter/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"/opt/flutter/.pub-cache/bin"
Activated webdev 2.7.1.
2酒甸、然后cd 到項目 flutter packages upgrade
終端再輸入
flutter packages upgrade
提示警告如下,可忽略
Warning: You are using these overridden dependencies:
! flutter_web 0.0.0 from path ../../packages/flutter_web
! flutter_web_ui 0.0.0 from path ../../packages/flutter_web_ui
Running "flutter pub upgrade" in hello_world...
3赋铝、接下來輸入 webdev serve
webdev serve
提示 -bash: webdev: command not found 這個時候解決第一步問題插勤。
找到.bash_profile 文件打開
把之前的 export PATH="$PATH":"/opt/flutter/.pub-cache/bin" 拷過來
并且配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/opt/flutter/bin/cache/dart-sdk/bin:$PATH
export PATH=/opt/flutter/bin:$PATH
接下來輸入
webdev serve
提示如下
webdev could not run for this project.
No pubspec.lock file found, please run "pub get" first.
然后輸入
pub get
4、接下來再輸入 webdev serve
提示如下
Downloading source_maps 0.10.9...
Downloading archive 2.0.13...
Downloading quiver 2.1.5...
Downloading dart_style 1.3.9...
Downloading intl 0.16.1...
Changed 65 dependencies!
hehuandeMacBook-Pro:spinning_square hehuan$ webdev serve
[INFO] Building new asset graph completed, took 1.3s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Serving `web` on http://127.0.0.1:8080
[INFO] Generating SDK summary completed, took 3.3s
[INFO] Running build completed, took 23.4s
[INFO] Caching finalized dependency graph completed, took 361ms
[INFO] Succeeded after 23.8s with 594 outputs (3161 actions)
[INFO] ------------------------------------------------------------------------
[INFO] Received request for entrypoint at http://127.0.0.1:8080/main.dart.bootst[INFO] Injected debugging metadata for entrypoint at http://127.0.0.1:8080/main.[INFO] Received request for entrypoint at http://localhost:8080/main.dart.bootst[INFO] Injected debugging metadata for entrypoint at http://localhost:8080/main.dart.bootstrap.js
看到http://127.0.0.1:8080/ 表示服務(wù)啟動成功
配上我的截圖
項目代碼和介紹的鏈接地址 https://gitee.com/wenbinzhou/flutter_web.git