一、配置环境
前提:已配置好flutter基础环境,然后配置flutter_web的运行环境
终端运行命令:flutter pub global activate webdev

运行完毕后会有一段红色警告,将警告内容复制

在根目录下运行命令
open .bash_profile
,将路径添加到环境变量中我的配置文件参考:

运行命令
source .bash_profile
更新环境
二、创建工程
以VSC为例(Android Studio不会哈哈)
在查看-命令面板中输入命令flutter
找到Flutter:New Web Porject创建工程

cd到新的工程下,更新环境:
flutter packages upgrade

通过命令
webdev serve
运行项目有没有运行报错???

顾名思义,dart 命令未找到,因为环境变量中并未配置(至少我没配置,已配置可忽略)
在flutterSDK中找到dart-sdk的bin文件夹将目录添加到bash_profile中
(参考本文中我的配置文件最后一段路径)

操作完毕后,再次执行
webdev serve
即可成功运行。
网友评论