Flutter快速入门实战

官方英文文档

Flutter中文网

flutter常用命令

1
2
3
flutter run --release
flutter devices #查看连接的设备
flutter doctor #检查环境

安装-环境搭建-debug-运行发布一个应用到手机上

  1. 下载flutter_macos_3.0.1-stable.zip
  2. 解压到~/flutter
  3. 配置环境变量,在~/.zshrc末尾添加export PATH="~/flutter/bin:$PATH"
  4. idea安装flutter插件并附带安装Dart插件
  5. 配置idea的flutter路径~/flutter
  6. 新建一个Flutter项目

IOS设置

  1. 安装Xcode
  2. 设置IOS模拟器,在idea或bash执行open -a Simulator
  3. 在idea项目上面右键,然后点击Flutter/Opne IOS module in Xcode
  4. 然后在Xcode里面点击运行即可
  5. (可选)启用其他平台执行flutter config --enable-linux-desktop
  6. 设置开发者账号,在Xcode-runner-setting-team添加苹果账号
  7. 点击即可debug测试
  8. iOS提示不受信任的开发者,点击设置-通用-VPN与设备管理-添加信任
  9. 断开数据线会提示In iOS 14+,debug mode Flutter apps can only 执行flutter run --release进行发布安装

常见问题

  1. 找不到ios设备,健康检查提示CocoaPods not installed

    解决:执行sudo gem install cocoapods安装cocoapods

    1
    2
    3
    4
    5
    6
    7
    #无sudo安装,报错
    gem install cocoapods --user-install
    #错误信息,解决,用sudo gem install cocoapods安装
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
    #include "ruby/config.h"
    ^~~~~~~~~~~~~~~
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks')
  2. 健康检查提示`HTTP host “https://maven.google.com/" is not reachable. Reason: An error

      occurred while checking the HTTP host: Operation timed out
    ✗ HTTP host "https://cloud.google.com/" is not reachable. Reason: An error
      occurred while checking the HTTP host: Operation timed out`
    

    解决:在~/.zshrc添加环境如下变量

    1
    2
    3
    # 国内用户需要设置
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn