目前公司項(xiàng)目從純iOS、Android端改為混合開發(fā),需要在原生項(xiàng)目中嵌入flutter開發(fā)的代碼,我當(dāng)前的flutter版本是 v1.12.13+hotfix.9-stable,使用過(guò)程中有些問(wèn)題,于是在項(xiàng)目上線后,對(duì)flutter做了升級(jí)處理,升級(jí)到 v1.20.2,升級(jí)后運(yùn)行項(xiàng)目報(bào)錯(cuò)如下:
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項(xiàng)目中用到了時(shí)間選擇器,并設(shè)置了主題DatePickerTheme,查看DatePickerTheme源碼發(fā)現(xiàn)在有一段官方注釋如下:
// 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版本已經(jīng)發(fā)生了變更,由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 {
重新運(yùn)行,成功!