【问题标题】:Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments未处理的异常:NoSuchMethodError:类 '_InternalLinkedHashMap<String, dynamic>' 没有具有匹配参数的实例方法 'cast'
【发布时间】:2020-12-19 11:56:10
【问题描述】:

我对 Flutter / Dart 还是有点陌生 我从 php json 文件中恢复数据,但它在颤振中显示错误。

E/flutter ( 7160): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: 
NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with 
matching arguments.
E/flutter ( 7160): Receiver: _LinkedHashMap len:1
E/flutter ( 7160): Tried calling: cast<Map<String, dynamic>>()
E/flutter ( 7160): Found: cast<RK, RV>() => Map<RK, RV>
E/flutter ( 7160): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)

【问题讨论】:

  • 检查堆栈跟踪并找出导致问题的行并发布。
  • 这一行的错误:final items = json.decode(response.body).cast>();

标签: android-studio flutter dart


【解决方案1】:

试试 final items = Map&lt;String, dynamic&gt;.from(json.decode(response.body));

【讨论】:

    猜你喜欢
    • 2021-11-07
    • 2019-11-20
    • 2021-04-20
    • 2022-11-24
    • 2021-02-26
    • 2020-12-20
    • 1970-01-01
    • 2022-11-21
    相关资源
    最近更新 更多