Flutter升級(jí)后iOS端flutter run 報(bào)錯(cuò)問(wèn)題解決

目前公司項(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)行,成功!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容