Flutter是什么
Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面。 Flutter可以与现有的代码一起工作。在全世界,Flutter正在被越来越多的开发者和组织使用,并且Flutter是完全免费、开源的。
安装
- 使用git将Flutter项目克隆到本地,
然后将Flutter添加到本地环境变量(终端)
cd 到准备好的文件夹
git clone -b dev https://github.com/flutter/flutter.git
- 配置
打开环境变量文件:
open ~/.bash_profile
WX20190726-110210@2x.png
保存后,再次执行这个文件:
source ~/.bash_profile
我们运行一下:
flutter doctor
第一次运行一个flutter命令(如flutter doctor)时,它会下载它自己的依赖项并自行编译。以后再运行就会快得多
- 错误
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
需要安装android studio并且设置好$ANDROID_HOME这个环境变量
安装好后,打开
bash_profile
open -e .bash_profile
在
bash_profile
里加上
export ANDROID_HOME="/Users/用户名/Library/Android/sdk" //android sdk目录,替换为你自己的
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
更新配置
source .bash_profile
- 错误
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
(or visit https://flutter.dev/setup/#android-setup for detailed
instructions).
If the Android SDK has been installed to a custom location, set
ANDROID_HOME to that location.
You may also want to add it to your PATH environment variable.
根据提示运行:
flutter doctor --android-licenses
然后根据提示一直y,y到结束为止。
- 错误
去App Store安装了xcode后,运行
[✗] iOS tools - develop for iOS devices
✗ libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
根据错误提示运行,例如:
brew update
...
如果重复提示 iOS toolchain - develop for iOS devices,进入
/usr/local/Cellar
目录删除libimobiledevice
、usbmuxd
和ideviceinstaller
库,重启电脑即可
- 错误
[!] Android Studio (version 3.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
WX20190728-012519@2x.png打开
Android Studio
软件 ->preferences
然后 我们就可以建立
flutter
的工程了
- 警告
[!] Connected device
! No devices available
连接手机即可
- 最终
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.8.2, on Mac OS X 10.13.6 17G5019, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[!] Xcode - develop for iOS and macOS (Xcode 10.1)
! CocoaPods out of date (1.6.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
brew upgrade cocoapods
pod setup
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.4)
[✓] Connected device (1 available)
CocoPods 警告我们也可以使用了
强迫症的解决方案
找出目前版本的pod路径
which pod
移除现有pod
rm -rf /usr/local/bin/pod
重新下载pod
sudo gem install cocoapods
- 创建项目
cd 到创建目录
//在当前路路径创建⼀一个新的名叫flutter_demo的新项⽬目
flutter create your_flutter_demo
//创建⼀一个可包含dart源码的flutter库
flutter create --template=package your_flutter_demo
//创建⼀一个域名为com.guahao的java语⾔言的flutter项⽬目(⽀支持object-C、swift、java、kotlin)
flutter create --org="com.guahao" -a java your_flutter_demo
在VS Code 面板中,按下快捷键 Ctrl + Shift + P 打开命令面板
在命令面板中输入 flutter
选择 flutter:New Project 选项创建新项目。
- IDE
这里我使用的Visual Studio Code进行开发
WX20190728-021740@2x.png设置中文
macOS 快捷键:command + shift + p
搜索:configure language
下载插件
shift + command + x
搜索
dart code
安装
搜索
flutter
安装
网友评论