41
16

More than 5 years have passed since last update.

Firestore と Dart で _InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>

Posted at

Firestoreのドキュメント内に階層化されたオブジェクトがある場合に、Dart側でMap<String,dynamic>として値を参照しようとしたところ、次のようなエラーメッセージが出力された。

_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>

具体的にはこのような構造のデータがある場合

{
  "name": "Bob",
  "songs": {
    "1": {
      "title": "Foo",
      "price": 100
    },
    "2": {
      "title": "Bar",
      "price": 200
    }
  }
}

こんなコードを書くと出力される。

final Map<String,dynamic> map = snapshot.data["songs"];

回避するにはこんなふうに書けば良い。

final Map<String,dynamic> map = new Map<String,dynamic>.from(snapshot.data["songs"]);

参考
https://github.com/flutter/flutter/issues/16589

41
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
16