【问题标题】:null check operator used on a null value in flutter 3.0Flutter 3.0 中用于空值的空值检查运算符
【发布时间】:2022-06-15 21:21:21
【问题描述】:

enter image description here

 class News {
  int? id;
  String? title;
  String? imageUrl;
}


return Container(
  child: Center(
    child: ListView(
      children: [
        Card(
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Image.network(_featuredNews.imageUrl!),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  _featuredNews.title!,
                  style: TextStyle(
                      fontSize: 18.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.black),
                ),
              ),

当我运行此代码时,空值检查运算符用于空值,我的颤振 3.0 请帮助我完成我的工作

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    也许是 _featuredNews.imageUrl!或 _featuredNews.title!是原因。

    你试试呢

    1. 在 Image.network 中使用 errorBuilder
    2. 或者改成like_featuredNews.title ?? '' 来处理
    3. 或通过“必需”变量接收变量 . . .

    【讨论】:

      【解决方案2】:

      添加这个

      _featuredNews.title ?? ""
      
      _featuredNews.imageUrl ?? ""
      

      【讨论】:

        猜你喜欢
        • 2022-01-18
        • 1970-01-01
        • 2021-02-25
        • 2023-01-05
        • 2022-01-05
        • 2021-08-30
        • 2021-12-03
        • 2021-11-06
        • 2021-06-17
        相关资源
        最近更新 更多