Mac电脑Flutter环境搭建及运行

此文章借鉴参考此博客:https://blog.csdn.net/ws1836300/article/details/130766889

注意:

*下载xcode 就包含git了,

*苹果芯片和intel 芯片需要的环境不同,苹果芯片需要安装:

Important: If you're installing on an Apple Silicon Mac, you must have the Rosetta translation environment available for some ancillary tools. You can install this manually by running:

javascript 复制代码
sudo softwareupdate --install-rosetta --agree-to-license

一、下载Flutter包

1.下载后解压flutter包:Mac Flutter SDK

然后将解压后的flutter文件夹放到某个不常动的目录下然,记住路径

二、mac终端-配置环境变量

1、执行命令: vim ~/.bash_profile

2、键盘输入i

3、复制代码粘贴

javascript 复制代码
export PATH=/你的Flutter下载路径/flutter/bin:$PATH  
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

4、按esc 然后输入 :wq 退出

5、执行命令: source ~/.bash_profile

6、执行命令flutter -h :

*如果提示:

command not found: flutter,请检查第3步,看下路径

*如果提示:

Manage your Flutter app development.表示可以了,执行第7条

7、执行命令: flutter doctor

三、下载VSCode

VsCode下载地址

四、安装VSCode下载插件

1.搜索dart

2.搜索flutter

五、创建应用

使用vscode初始化项目(必须先安装flutter插件),在vscode里同时按住

shift + command + p

然后输入Flutter: New Project

如果提示:flutter 初始化失败,就是flutter文件没有被找到引起的,可能是你放置的文件位置不允许被访问,(这是苹果新加了一个保护机制Mac提示operation not permitted解决方式_Holidaylovesam的博客-CSDN博客),报错如下:

javascript 复制代码
EPERM: operation not permitted, open '/Users/你的名称/Downloads/flutter/version'
Error: EPERM: operation not permitted, open '/Users/你的名称/Downloads/flutter/version'
	at Object.openSync (node:fs:585:3)
	at Object.func [as openSync] (node:electron/js2c/asar_bundle:5:1812)
	at Object.readFileSync (node:fs:453:35)
	at e.readFileSync (node:electron/js2c/asar_bundle:5:9160)
	at getSdkVersion (/Users/weishuai/.vscode/extensions/dart-code.dart-code-3.64.0/out/dist/extension.js:25309:14)
	at SdkUtils...

你可以把flutter文件移出到你项目下的文件夹里。至于导入的这个:

"export PATH=/你的Flutter下载路径/flutter/bin:$PATH "可以先不用管他。

如果有这个提示:

你可以选择Locate SDK ,加载本地文件夹里的 flutter SDK 文件即可:

添加后,在弹出的这个 Application 选项,直接选择即可。

出现这两个框,说明创建成功了:


打开界面如下所示:

六、模拟器调试

iOS模拟器运行:

打开xcode, VsCode中选模拟器设备

或者直接通过命令打开模拟器:

javascript 复制代码
open -a Simulator

然后运行项目;

( 修改代码后,command+S 自动热加载)

Android模拟器

web(windows):

web(macOS):

相关推荐
绝世唐门三哥20 分钟前
Mac 免费 GIF 录制软件全攻略:下载、安装与使用指南
macos·gif
2501_9159184124 分钟前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
三翼鸟数字化技术团队1 小时前
电视版智家App兼容触摸和遥控器交互方式
app
farewell-Calm1 小时前
01_Android快速入门
android
未来猫咪花1 小时前
flutter 确实不需要 hooks
flutter
helloCat1 小时前
记录CI/CD自动化上传AppGallery遇到的坑
android·前端·api
WordPress学习笔记2 小时前
wordpress根据页面别名获取该页面的链接
android·wordpress
2501_916007472 小时前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
音浪豆豆_Rachel2 小时前
Flutter鸿蒙化之深入解析Pigeon可空返回与参数设计:nullable_returns.dart全解
flutter·harmonyos
2501_916007473 小时前
React Native 混淆在真项目中的方式,当 JS 和原生同时暴露
javascript·react native·react.js·ios·小程序·uni-app·iphone