我遇到以下错误在执行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": []
}
这就是我的设计方式,可以帮助我解决该错误,同时还建议我学习颤振中的其他循环结构,
.
.
.
(_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(),
.
.
.
错误:
══╡小工具图书馆的例外情况╞══════════════════════════════════════ ═════════════════════
在构建HomeBody(dirty,依赖项时,引发了以下_TypeError:[_InheritedTheme,
MediaQuery,_LocalizationsScope- [GlobalKey#a426a]],状态:_HomeBodyState#1a025):
'_InternalLinkedHashMap
答案 0 :(得分:0)
String key = _allMatches.elementAt(index);
您在索引处的元素是不是字符串。而且你知道。它由用户名和user_id组成,这是另一张地图,您已经在其他地方正确使用了它。
答案 1 :(得分:0)
尝试此
var _allMatches = [];
_allMatches = matchResponseBody["all_matches"];