Flutter开发 -flutter1.22.x升级踩坑记

678 阅读2分钟

1.22版本相关:

flutterSDK:1.22.1(目前最新版为1.22.2)
dart:2.10.1

LHHdeMacBook-Pro:next zcy$ dart --version
Dart SDK version: 2.10.1 (stable) (Tue Oct 6 10:54:20 2020 +0200) on "macos_x64"
LHHdeMacBook-Pro:next zcy$ flutter --version
Flutter 1.22.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f30b7f4db9 (2 weeks ago) • 2020-10-08 10:06:30 -0700
Engine • revision 75bef9f6c8
ToolsDart 2.10.1

Xode:12.1(安卓同学酌情升级)
pod:iOS升级到1.10.0
安卓SDK:10.0(Q)

可能会出现的问题:
1.警告

LHHdeMacBook-Pro:dev_1.22.1 zcy$ flutter build ios
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at
https://flutter.dev/go/android-project-migration
to migrate your project.

这个查了下,说是安卓的兼容性问题,不影响iOS使用,安卓不清楚,安卓同学看下能不能解决;

2.flutter版本升级,上面已经给了dart版本号,尽量都升级到最新;

3.错误提示,如果有的话,有两处,不用处理

LinearGradient(
    begin: Alignment.centerRight,
    end: Alignment.centerLeft,
    colors: [///colors报错,提示不存在,实际上存在的,改成List不报错,但是不正确。
      Color(0xFFFF822C),
      Color(0xFFFF4416),
      Color(0xFFFF4416),
    ]),


AnimationController(
  duration: kThemeAnimationDuration,
  vsync: vsync,   ///vsync报错,提示不存在,改成TickerProvider不报错,和colors一样的问题

);

这个问题,先前全改过List和TickerProvider,后来又提示要改回来,重启studio后恢复正常,猜测可能是系统库的依赖问题。

4.ChineseCupertinoLocalizations新增两个方法,必须重写,否则报错;

5.3中LinearGradient定义的时候不能使用const定义,要使用var;

6.依赖问题,之前不依赖其他的plugin也可以引用头文件,现在必须要依赖对应的plugin;

7.命名冲突问题,若是和系统库中类名冲突,需要解决,可通过’hide xxxx’,‘as xxx’,或者改名的方式来处理;

8.看下这个是什么
This requires the ‘control-flow-colllections’ language feature to be enabled.
在这里插入图片描述
在这里插入图片描述

查了下,说是通过添加如下可以解决,结果还是存在

analyzer:
  enable-experiment:
    - control-flow-collections
    - spread-collections

最后才发现是因为环境中设置dart最低版本过低导致的,在plugin中的yaml中修改环境如下即可:

environment:
  sdk: ">=2.7.0 <3.0.0"

9.idevice_id和iproxy文件变化了,Flutter中,idevice_id和iproxy无法打开的问题(真机调试卡在启动页进不去),这篇博客中给出的路径有变化,可以自己打开看看里面的文件变化,影响不大,iproxy地址没变,弹出权限提醒时,还按照原来的操作处理即可。
在这里插入图片描述

10.podfile升级,贴一下博主更新过的podfile给大家做参考:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup
target Runner do
  platform :ios, '10.0'
  use_frameworks!
  use_modular_headers!
  source 'https://github.com/aliyun/aliyun-specs.git'
  source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
  pod 'Flutter', :path => 'Flutter'
  
  pod 'xxxx'
  pod 'xxxx'
  pod 'xxxx'
  pod 'xxxx'
  pod 'xxxx'

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end