【问题标题】:<asynchronous suspension> Error in Flutter<异步挂起> Flutter中的错误
【发布时间】:2021-03-10 15:25:35
【问题描述】:

我是 Flutter 的新手,我不知道该怎么做。任何帮助将不胜感激!

E/flutter ( 6560): <asynchronous suspension>
E/flutter ( 6560): 
E/flutter ( 6560): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
E/flutter ( 6560): Receiver: null

【问题讨论】:

标签: android firebase flutter asynchronous dart


【解决方案1】:

错误只是说明运算符 [] 是在不包含 Map 对象的变量上调用的,而是 null。常见的解决方法是在每次访问 map 的属性之前检查 null 或使用 ?? 为 map 提供默认值。

你可以做一些事情,比如创建一个私有方法:

getValue(String key) {return map != null ? map[key] : null;}

并在整个小部件中使用此方法来访问 Map 中的值。

如果不是这样,请尝试提供a minimal, complete and verifiable example。以便每个人都可以检查可能导致您出现此错误的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-26
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2019-02-08
    • 1970-01-01
    相关资源
    最近更新 更多