- 安装Dart SDK
brew tap dart-lang/dart
brew install dart
- 配置VSCode
安装Dart、Code Runner插件 - 下载Flutter SDK
- 解压Flutter SDK压缩包到目标路径
- 配置flutter的PATH环境变量
比如我的,在.zshrc文件中增加下面一行:
export PATH="$PATH:/Users/wlm/workspace/development/flutter/bin"
通过下面两个命令验证PATH环境变量是否添加成功:
echo $PATH
which flutter
- 通过命令行创建一个Flutter应用
flutter create my_app
- 启动应用
cd my_app
flutter run
报错:
Multiple devices found:
macOS (desktop) • macos • darwin-x64 • macOS 12.1 21C52 darwin-x64
Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.124
[1]: macOS (macos)
[2]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 1
Launching lib/main.dart on macOS in debug mode...
ProcessException: Process exited abnormally:
xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH
Command: xcrun xcodebuild -list -project Runner.xcodeproj
这是因为Mac电脑没有Xcode,安装后再次运行,出现下面的提示:
Building flutter tool...
Multiple devices found:
macOS (desktop) • macos • darwin-x64 • macOS 12.1 21C52 darwin-x64
Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.124
[1]: macOS (macos)
[2]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 1
Running "flutter pub get" in my_app... 505ms
Launching lib/main.dart on macOS in debug mode...
Building macOS application...
Syncing files to device macOS... 152ms
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
💪 Running with sound null safety 💪
An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:53719/92xA0GO6XBc=/
The Flutter DevTools debugger and profiler on macOS is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:53719/92xA0GO6XBc=/
Lost connection to device.
界面运行起来如下: