【问题标题】:How to remove the 'is null error' in Flutter BLOC pattern?如何消除 Flutter BLOC 模式中的“为空错误”?
【发布时间】:2021-10-13 07:42:54
【问题描述】:

当我运行我的应用并选择我喜欢的狗品种并喜欢它时,我收到一条错误消息 -

════════ Exception caught by gesture ═══════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The method 'contains' was called on null.
Receiver: null
Tried calling: contains(Instance of 'BreedsModel')

likeList 列表包含我喜欢的所有犬种。我该如何解决这个问题?

这是我的代码的链接 - My Code

【问题讨论】:

    标签: android flutter error-handling bloc


    【解决方案1】:

    这是因为你在一个空变量上调用 contains 函数。

    尝试打印您正在调用的变量 contains 函数。

    print(likedList);
    //output will "null"
    

    确保您处理的是空值

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 2019-02-07
      • 2023-03-12
      • 2019-08-09
      • 2019-11-20
      • 2019-06-13
      • 2019-07-19
      • 1970-01-01
      • 2020-08-16
      相关资源
      最近更新 更多