Mac搭建Fluter应用环境
1、创建一个路径。例如我创建是:
/Users/chenghui/
然后创建一个文件夹:
development
把下载好的Fluter 解压到当前目录下: development
/Users/chenghui/development
2、当你看官网的时候,Mac环境配置 许多小伙伴都是卡在了配置环境变量这里。
基本我们都要创建一个 .zshrc文件,默认情况下不存在。
创建步骤:
1、开放终端
键入
touch ~/.zshrc 以创建相应的文件。(该touch 命令将在当前目录中创建.zshrc,但它将被隐藏)
击中 return
2、要查看/打开,~/.zshrc您可以执行以下两项操作之一:
2.1、打开查找器 => 按 Cmd + Shift + . (显示或隐藏文件,不要随便删除这些隐藏文件)
============ OR ====================
2.2、打开终端 => 类型 open ~/.zshrc
3、配置永久路径
但你打开 open ~/.zshrc
// 默认是这样子的:
export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
把 [PATH_TO_FLUTTER_GIT_DIRECTORY] 替换成你自己的目录路径。
这里我的是:/Users/chenghui/development
export PATH="$PATH:/Users/chenghui/development/flutter/bin"
输入后 ~等待~~ 回车的效果:
chenghui@chenghuideMacBook-Pro-2 development % open ~/.zshrc
chenghui@chenghuideMacBook-Pro-2 development % source $HOME/.bash_profile
[Chenghui-\u \W]$ echo $PATH
/Users/chenghui/.rbenv/shims:/Users/chenghui/.rbenv/bin:/usr/local/opt/openssl/bin:/Users/chenghui/.rbenv/shims:/Users/chenghui/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/chenghui/.rvm/bin:/Users/chenghui/flutter/bin:/Users/chenghui/development/flutter/bin
[Chenghui-\u \W]$
如果选择了:(开发二进制文件预下载(可选操作))~~~ 等待.....
[Chenghui-\u \W]$ flutter precache
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ Note: The Google Privacy Policy describes how data is handled in this ║
║ service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://www.google.com/intl/en/policies/privacy/ ║
╚════════════════════════════════════════════════════════════════════════════╝
继续等待....
Downloading Android Maven dependencies...
(This is taking an unexpectedly long time.) ⣾
最终下载是这样子吧:
Downloading Android Maven dependencies...
272.6s (!)
接着,查看当前是否还要安装其他依赖:flutter doctor
[Chenghui-\u \W]$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76,
locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[!] Android Studio (version 3.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.44.2)
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
[Chenghui-\u \W]$
它说我的Android Studio 和 IntelliJ IDEA Ultimate Edition 没有安装插件。但是Xcode 和 VS Code 是可以的。
4、Xcode 和 Android Studio 的安装基本跟着官网就可以了...... 忽略!!!
5、使用终端创建一个应用:
[Chenghui-\u \W]$ flutter create my_app
又是漫长的等待.... This is taking an unexpectedly long time.
$ cd my_app
$ flutter run

fluterApp.jpg
链接:https://www.jianshu.com/p/637a20452582
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】