我用的是Mac 其它电脑类似
1、打开终端
cd 到项目路径下
然后终端 输入
flutter packages pub global activate webdev
提示下面内容,警告去path环境变量文件里
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/ 表示服务启动成功
配上我的截图
截屏2020-11-13 下午5.45.36.png项目代码和介绍的链接地址 https://gitee.com/wenbinzhou/flutter_web.git
网友评论