簡體   English   中英

顫振錯誤:輸入&#39;_InternalLinkedHashMap<String, dynamic> &#39; 不是 &#39;String&#39; 類型的子類型

[英]Flutter Error : type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'

我在執行 ListView.builder 時遇到以下錯誤,我只是想顯示滾動列表視圖,所以我從 API Call 獲取對象,

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": []
}
 

這就是我的設計方式,幫助我解決這個錯誤還建議我在 flutter 中學習不同的循環結構,在此先感謝。

.
    .
    .        
(_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(dirty,dependencies:[_InheritedTheme,MediaQuery,_LocalizationsScope-[GlobalKey#a426a]],狀態:_HomeBodyState#1a025) : type '_InternalLinkedHashMap<String, dynamic>' 不是類型 'String' 的子類型相關的導致錯誤的小部件是:

String key = _allMatches.elementAt(index);

您在索引處的元素不是字符串。 你知道的。 它由用戶名和用戶 ID 組成,它是另一個地圖,您已經在其他地方正確使用它。

試試這個

var _allMatches = [];
 _allMatches = matchResponseBody["all_matches"];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM