Flutter跨平台应用

Flutter的安装和配置

2019-02-12  本文已影响86人  TitanCoder
Flutter

跨平台框架

Flutter安装

系统要求

要安装并运行Flutter,您的开发环境必须满足以下最低要求:

获取Flutter SDK

下载SDK

Flutter_SDK

环境配置

# Flutter 相关配置
# xxx是你自己的Flutter文件夹路径
export PATH=/xxx/Flutter/bin:$PATH

由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

注意, 此镜像为临时镜像,并不能保证一直可用,读者可以参考详情请参考 Using Flutter in China 以获得有关镜像服务器的最新动态

保存文件, 并更新当前配置

# 执行命令
source ~/.bash_profile

验证flutter/bin目录是否在你的PATH

# 执行下面命令
echo $PATH

如果安装成功, 会输出类似/xxx/Flutter/bin的路径

安装开发工具

安装Android Studio

安装Xcode

App Store搜索最新版本Xcode下载安装即可

VSCode

开发IDE,直接去官网下载安装即可

环境配置检测

通过flutter doctor命令来执行Flutter的安装程序了,经过一段时间的下载和安装,Flutter会输出安装结果(时间可能会比较久)

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-NZ)
[!] Android toolchain - develop for Android devices (Android SDK 26.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ Missing Xcode dependency: Python module "six".
    Install via 'pip install six' or 'sudo easy_install six'.
    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
    To install:
        brew install cocoapods
        pod setup
[✓] Android Studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Android Studio (version 3.0)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2017.1.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.24.1)
[!] Connected devices
    ! No devices available

! Doctor found issues in 5 categories.

开发工具

运行flutter doctor命令可看到相关信息

Android Studio

android_flutter

这时候在命令行运行flutter doctor,可以看到Android Studio已经好了

[✓] Android Studio (version 3.2)

iOS配置

[!] iOS toolchain - develop for iOS devices

# 可能出现的命令, 若出现, 依次执行出现的命令即可, 未出现的可不执行
$ brew install --HEAD usbmuxd
$ brew link usbmuxd
$ brew install --HEAD libimobiledevice
$ brew install ideviceinstaller ios-deploy cocoapods
$ pod setup

这时候在命令行运行flutter doctor,可以看到iOS相关配置也好了

VSCode插件

在扩展中搜索FlutterDart安装后, 重载即可

配置完成

此刻, 在运行flutter doctor命令, 应该就没有问题了

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.3 18D109, locale
    zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.0)
[✓] VS Code (version 1.30.2)
[✓] Connected device (1 available)

• No issues found!

创建Flutter应用

CSCode创建

中文版: vscode -> 查看 -> 命令面板 -> Flutter: new project -> 输入项目名称

注意: 项目名称不支持大写字母

Android Studio创建

打开Android studio就可以看见Flutter工程模板如下

android_create_flutte

命令创建

flutter create helloflutter

这里创建了一个名为helloflutterDart package

flutter create --org com.example --template=plugin helloflutter
flutter create --template=plugin -i swift -a kotlin helloflutter

参考文章

初识Flutter, 总结的可能也不准确, 不足之处还望海涵, 后续会继续优化相关文章

上一篇下一篇

猜你喜欢

热点阅读