Flutter for web 开发环境搭建

1. 搭建环境

  • 首先安装flutter sdk
  • Clone the flutter_web source code(检出 flutter_web的源码)

git clone https://github.com/flutter/flutter_web.git

  • Install the flutter_web build tools(安装 flutter_web的开发工具)

flutter pub global activate webdev

  • Ensure that the $HOME/.pub-cache/bin directory is in your path, and then you may use the webdev command directly from your terminal. (前一步安装后会提示实际路径,如 E:\flutter\.pub-cache\bin)

flutter内部使用的一些命令无法找到,实际上是dart sdk的path没有设置,增加E:\flutter\bin\cache\dart-sdk\bin 到path就ok了。

Locate the file flutter_console.bat inside the flutter directory. Start it by double-clicking.

 

  • Run the hello_world example

cd examples/hello_world/

flutter pub upgrade

webdev serve(可能需要先执行pub get)

 

Tools support for Flutter web development

Visual Studio Code

Visual Studio Code supports Flutter web development with the v3.0 release of the Flutter extension.

  • install the Flutter SDK
  • set up VS Code
  • configure VS Code to point to your local Flutter SDK
  • run the Flutter: New Web Project command from VS Code
  • after the project is created, run your app by pressing F5 or "Debug -> Start Debugging"
  • VS Code will use the webdev command-line tool to build and run your app; a new Chrome window should open, showing your running app

 

Configuring Flutter to use a mirror site

If you’re installing or using Flutter in China, it may be helpful to use a trustworthy local mirror site that hosts Flutter’s dependencies. To instruct the Flutter tool to use an alternate storage location, you need to set two environment variables, PUB_HOSTED_URL and FLUTTER_STORAGE_BASE_URL, before running the flutter command.

Taking MacOS or Linux as an example, here are the first few steps in the setup process for using a mirror site. Run the following in a Bash shell from the directory where you wish to store your local Flutter clone:

$ export PUB_HOSTED_URL=https://pub.flutter-io.cn $ export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

 

使用vs code的  Flutter: New Web Project  创建的项目无法运行的问题(不能pub get):

dependency_overrides:

flutter_web:

git:

url: https://github.com/flutter/flutter_web

path: packages/flutter_web

flutter_web_ui:

git:

url: https://github.com/flutter/flutter_web

path: packages/flutter_web_ui

缺省生成的依赖没对。

修改方式1(直接使用本地下载的flutter web项目):

dependency_overrides:

flutter_web:

path: E:/test/flutter/flutter_web/packages/flutter_web

flutter_web_ui:

path: E:/test/flutter/flutter_web/packages/flutter_web_ui

 

修改方式2(参考https://dart.dev/tools/pub/dependencies , url: https://github.com/flutter/flutter_web 修改为 url: https://github.com/flutter/flutter_web.git):

pub assumes that the package is in the root of the Git repository. To specify a different location in the repo, use the path argument:

dependencies: kittens: git: url: git://github.com/munificent/cats.git path: path/to/kittens

The path is relative to the Git repo’s root.

 

dependency_overrides:

flutter_web:

git:

url: https://github.com/flutter/flutter_web.git

path: packages/flutter_web

flutter_web_ui:

git:

url: https://github.com/flutter/flutter_web.git

path: packages/flutter_web_ui

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值