運(yùn)行 flutter web 的第一個(gè)項(xiàng)目

我用的是Mac 其它電腦類(lèi)似

1、打開(kāi)終端

cd 到項(xiàng)目路徑下
然后終端 輸入

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 到項(xiàng)目 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、接下來(lái)輸入 webdev serve

webdev serve

提示 -bash: webdev: command not found 這個(gè)時(shí)候解決第一步問(wèn)題。
找到.bash_profile 文件打開(kāi)
把之前的 export PATH="$PATH":"/opt/flutter/.pub-cache/bin" 拷過(guò)來(lái)

并且配置

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

接下來(lái)輸入

webdev serve

提示如下

webdev could not run for this project.
No pubspec.lock file found, please run "pub get" first.

然后輸入

pub get

4、接下來(lái)再輸入 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ù)啟動(dòng)成功

配上我的截圖

截屏2020-11-13 下午5.45.36.png

項(xiàng)目代碼和介紹的鏈接地址 https://gitee.com/wenbinzhou/flutter_web.git

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容