【问题标题】:The argument type 'String"?"' can't be assigned to the parameter type 'String'参数类型“字符串”?“”不能分配给参数类型“字符串”
【发布时间】:2021-10-13 10:25:41
【问题描述】:

参数类型“字符串?”不能分配给参数类型'String'

如何传递参数?

【问题讨论】:

标签: flutter


【解决方案1】:

你可以试试这个

child: TipsCard(
//
image:tipsPages[i]["image"] as String,//
)

【讨论】:

    【解决方案2】:

    你可以这样做:

    //...
    
    child: TipsCard(
    //...
    image: tipsPages[i]["image"] ?? "", // Replace this blank "" with a default image url of your choice
    ),
    

    【讨论】:

    • 它的工作谢谢你,但我想问你为什么在初始化 char “?”像 (String?) 以及如何删除此功能? @巴赫
    • @MSameer 这是 Dart 2.0 引入的一个功能,有点像让 Dart 成为空安全语言的革命性变化,所以不使用它的唯一方法是将 Dart 转换回 1.0。 ? 表示该变量可以为空。我的建议是学习使用此功能而不是关闭它,因为它可以帮助我们避免空值的潜在错误。 Flutter 团队有一个非常不错的视频:youtube.com/watch?v=iYhOU9AuaFs
    猜你喜欢
    • 2021-10-21
    • 2021-09-04
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多