目前公司项目从纯iOS、Android端改为混合开发,需要在原生项目中嵌入flutter开发的代码,我当前的flutter版本是 v1.12.13+hotfix.9-stable,使用过程中有些问题,于是在项目上线后,对flutter做了升级处理,升级到 v1.20.2,升级后运行项目报错如下:
Xcode's output:
↳
../../../../../flutter/flutter_sdk/.pub-cache/hosted/pub.flutter-io.cn/flutter_datetime_picker-1.3.8/lib/src/datetime_picker_theme.dart:6:28: Error: Type
'DiagnosticableMixin' not found.
class DatePickerTheme with DiagnosticableMixin {
^^^^^^^^^^^^^^^^^^^
../../../../../flutter/flutter_sdk/.pub-cache/hosted/pub.flutter-io.cn/flutter_datetime_picker-1.3.8/lib/src/datetime_picker_theme.dart:6:7: Error: The type
'DiagnosticableMixin' can't be mixed in.
class DatePickerTheme with DiagnosticableMixin {
^
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the precompiled application for the device.
原因是flutter项目中用到了时间选择器,并设置了主题DatePickerTheme,查看DatePickerTheme源码发现在有一段官方注释如下:
// Migrate DiagnosticableMixin to Diagnosticable until
// https://github.com/flutter/flutter/pull/51495 makes it into stable (v1.15.21)
class DatePickerTheme with DiagnosticableMixin {
DatePickerTheme混入的DiagnosticableMixin在flutter v1.15.21版本已经发生了变更,由DiagnosticableMixin改为了Diagnosticable。
解决方案
我们可以直接用 Diagnosticable 替换 DiagnosticableMixin,如下:
// Migrate DiagnosticableMixin to Diagnosticable until
// https://github.com/flutter/flutter/pull/51495 makes it into stable (v1.15.21)
class DatePickerTheme with Diagnosticable {
重新运行,成功!