KARTHIKEYAN N
KARTHIKEYAN N

Reputation: 81

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

I have Following Error While doing ListView.builder, am just trying to display scrolled list view so i get object from API Call ,

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

[screen shot link]

Api Call Result :

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

This is how i designed, help me to resolving this error also suggest me to learn different looping structure in flutter , thanks in advance.

.
    .
    .        
(_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(),
    .
    .
    .

Error :

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following _TypeError was thrown building HomeBody(dirty, dependencies: [_InheritedTheme, MediaQuery, _LocalizationsScope-[GlobalKey#a426a]], state: _HomeBodyState#1a025): type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' The relevant error-causing widget was:

Upvotes: 1

Views: 158

Answers (2)

Aamil Silawat
Aamil Silawat

Reputation: 8239

Try out this

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

Upvotes: 0

nvoigt
nvoigt

Reputation: 77354

String key = _allMatches.elementAt(index);

Your element at the index is not a string. And you know that. It consists of username and user_id, it's another map, you are already using it correctly elsewhere.

Upvotes: 0

Related Questions