在群里会碰到各种各样的奇葩问题,每个版本都或多或少带点坑。
稍微记录下,否则下次可能会忘记何时出现的。
遇到的疑难杂症
升级到 Xcode 14 后报 requires a development team
官方跟进 issue:flutter/flutter#111475
目前在 ios/Podfile
中指定 DEVELOPMENT_TEAM
即可。两种方案:
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["DEVELOPMENT_TEAM"] = 'Team ID (可在 Runner.xcodeproj 找到)'
end
end
end
end
或
post_install do |installer|
dev_team = ""
project = installer.aggregate_targets[0].user_project
project.targets.each do |target|
target.build_configurations.each do |config|
if dev_team.empty? and !config.build_settings['DEVELOPMENT_TEAM'].nil?
dev_team = config.build_settings['DEVELOPMENT_TEAM']
end
end
end
installer.pods_project.targets.each do |target|
if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
target.build_configurations.each do |config|
config.build_settings['DEVELOPMENT_TEAM'] = dev_team
end
end
end
end
在 didChangeAppLifecycleState
中获取剪贴板数据为空(在 Android 11 上非常明显)
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
WidgetsBinding.instance.addPostFrameCallback((_) {
// 读取剪贴板
});
}
}
Text
中英文混排,如何对齐?
Text(
textHeightBehavior: TextHeightBehavior(
applyHeightToLastDescent: false,
),
)
在使用 Animation
的时候,突然间出现了 parent != null
或者 called on null
的错误
这个问题源自于两个人的示例,在他们的代码中,发现他们将 AnimationController
进行了向下传递再绑定的操作。一个出现了 RenderBox
计算空调用的错误,一个出现了 Animation
的 parent
为空的错误。
经过几个步骤的排查,基本断定是因为传入的 Widget
被重新创建了 Element
。很巧,两人的 Stateless/StatefulWidget
都不是终值。在绑定了 TickerProvider
的页面更新时,由于 Element
被重建了,导致了 controller 的丢失,最终空调用。
Android 打包时缺少 debug 或 profile 文件
Android Gradle Plugin 4.x 的深渊巨坑,三种解决方案:
- 将 Flutter 升级到 2.x,该问题貌似已经被解决;
- 降回 3.6.4;
- 每次打包时,先构建 debug/profile ,再构建 release。
各个稳定版本中存在的问题
3.0.x
BindingBase
现在默认不可空,原本使用了!
或?
的 package 在 3.0 上统统警告。因此我写了一个 bindings_compatible 专门用于桥接跨版本,简单粗暴地使用as
而不用空操作符就可以修复这个问题。
2.10.x
- flutter/flutter#100800 修复了长截图问题。
2.5.x
- building for iOS Simulator, but linking in an object file built for iOS, for architecture 'arm64',在 Podfile 中修改以下内容
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386 arm64' # 加入这行
2.0.x
- iOS 部分设备连接等待超时,新版本已提供了 discoveryTimeout 修改。
1.20.x
- InteractiveViewer 手势缩放几乎无法使用,相关 issues:
- Gradle plugin 4.0 无法正常 build release。flutter/flutter#58247
- FlutterView 需要接入 AutoFocus 相关 API,这项改动与 Boost 开发有关。alibaba/flutter_boost#814
1.17.x
- Deprecated accentIconTheme API usage flutter/flutter#56639
- iOS OpenGL 生命周期不兼容 flutter/flutter#60196
ZoomPageTransition
会导致新页面 build 三次 flutter/flutter#58686FadeUpwardsTransition
->ZoomPageTransition
flutter/flutter#51538WAKE_LOCK
权限异常地被请求 flutter/flutter#49912- 自1.17起,调用
configureFlutterEngine
时需要 super。此前不用,如果调用了会造成 plugins 二次注册。