当前位置: 首页 > 知识库问答 >
问题:

颤振错误:类型“\u InternalLinkedHashMap”不是类型“String”的子类型

闾丘淇
2023-03-14

我有以下错误而做ListView.builder,我只是想显示滚动列表视图,所以我从API调用对象,

List _allMatches = new List();
 _allMatches = matchResponseBody['all_matches'];//here i have assign to list variable

[屏幕截图链接]

API调用结果:

{
    "status": 200,
    "all_matches": [
        {
            "user_id": "212",
            "username": "Thangaraju",
            
        },
        {
            "user_id": "210",
            "username": "J. Balamurugan",
            
        },
        {
            "user_id": "208",
            "username": "Iyyanar k",
           
        },
    ],
    "who_viewed_me": [],
    "interests": []
}
 

这就是我的html" target="_blank">设计,帮助我解决这个错误也建议我学习颤振中不同的环结构,提前感谢。

.
    .
    .        
(_allMatches.isNotEmpty)
            ? MatchesTitleBlock(allMatchesLinkID: allMatchesLinkID)
            : SizedBox(),
        // buildNewMatchesBlock(),
        (_allMatches.isNotEmpty)
            ? Container(
                padding: EdgeInsets.all(10.0),
                height: 180.0,
                child: Stack(
                  children: <Widget>[
                    ListView.builder(
                        scrollDirection: Axis.horizontal,
                        itemCount: _allMatches.length,
                        itemBuilder: (BuildContext ctxt, int index) {
                          String key = _allMatches.elementAt(index);
                          return new Column(
                            children: <Widget>[
                              Card(
                                child: InkWell(
                                  splashColor: AppColors.CARD_SPLASH_COLOR,
                                  onTap: () {
                                    debugPrint("Card Tapped...");
                                  },
                                  child: Container(
                                    width: _card_height,
                                    height: _card_width,
                                    color: AppColors.PRIMARY_CARD_BG_COLOR,
                                    child: Image.asset(
                                        "assets/images/sample_user.png"),
                                  ),
                                ),
                              ),
                              Text(_allMatches[index]['username'],
                                  style: TextStyle(
                                      fontSize: 14.0,
                                      fontWeight: FontWeight.bold)),
                              Text("30 yrs,5'.4''",
                                  style: TextStyle(
                                      fontSize: 10.0,
                                      fontWeight: FontWeight.normal)),
                            ],
                          );
                        }),
                  ],
                ),
              )
            : SizedBox(),
    .
    .
    .

错误:

小部件库 ╞═══════════════════════════════════════════════════════════ 引起的异常以下_TypeError被抛出构建HomeBody(脏,依赖:[_InheritedTheme, MediaQuery,_LocalizationsScope-[GlobalKey#a426a]],状态:_HomeBodyState#1a025):类型'_InternalLinkedHashMap

共有2个答案

燕嘉颖
2023-03-14

试试这个

var _allMatches = [];
 _allMatches = matchResponseBody["all_matches"];
燕禄
2023-03-14
String key = _allMatches.elementAt(index);

索引处的元素不是字符串。你知道的。它由用户名和用户id组成,是另一个映射,您已经在其他地方正确使用了它。

 类似资料: