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
  3. (该问题似乎未解决)提示错误Searching for inspections failed: undefined method 'map' for nil:NilClass

    解决:执行sudo arch -x86_64 gem install ffi

  4. 执行flutter doctor提示

    1
    2
    [!] Proxy Configuration
    ! NO_PROXY is not set

    解决:执行vim .zshrc添加export NO_PROXY=localhost,127.0.0.1然后保存。

  5. 苹果IOS:xcode提示“codesign 想要访问您的钥匙串中的密钥”

    解决(最终采用):钥匙串访问APP=>登录=>我的证书=>双击“Apple Development:xxx“(这个选择系统,使用的签名的开发证书)=>访问控制=>允许所有应用

    解决方案二(采用):一直输用户名和密码大概8次左右

  6. 出现错误Error (Xcode): File not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a

    解决:将Podfile文件内容末位post_install do |installer|..... end替换为

    1
    2
    3
    4
    5
    6
    7
    8
    9
    post_install do |installer|
    installer.generated_projects.each do |project|
    project.targets.each do |target|
    target.build_configurations.each do |config|
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
    end
    end
    end
    end

    在ios目录,执行命令pod install