【问题标题】:Flutter IOS _CastError颤振 IOS _CastError
【发布时间】:2022-11-30 05:26:32
【问题描述】:

我目前正在开发一个 flutter 应用程序。我已经在 Android 上测试了一个功能并且一切正常,当我在 IOS 上测试它时,不幸的是调用了以下错误:

_CastError (type 'Contract' is not a subtype of type 'Damage' in type cast)

错误所指的代码如下:

final Damage damage = item as Damage;
return Scaffold(
  floatingActionButton: FloatingActionButton(
    tooltip: 'Add',
    onPressed: () {
      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (BuildContext context) => AddDocumentsPage(
            damage: damage,
          ),
        ),
      );
    },
    child: Icon(Icons.add),
  ),
  body: DocumentsList(
    attribute: 'date',
    documentable: item,
  ),
);

【问题讨论】:

    标签: ios flutter dart


    【解决方案1】:

    使用as 关键字时应格外小心。您的 item 很可能不是 Damage 类型,因此不能转换为一个。 您最好的选择是创建一个新的 Damage 对象并使用您需要的来自 item 的数据来实现它。 希望这可以帮助!

    【讨论】:

      猜你喜欢
      • 2021-05-31
      • 2020-08-25
      • 1970-01-01
      • 2020-07-29
      • 2021-01-18
      • 2021-10-26
      • 2020-10-13
      • 2021-01-07
      • 2022-11-15
      相关资源
      最近更新 更多