For loop 带json子列表的循环颤振
我有一个json,它有一个列表值,我想在gridview.builder下使用这个值, 我试着用一个“for”来表示,只取第一个列表的第一项,然后根据相关索引的长度重复,比如第一个(878878)第二个(878878)等。 我错过了什么 我的目标是在相关卡片旁边获得相关的类型ID(稍后我会将它们命名),但现在看起来是这样的 下面是我的代码和json示例For loop 带json子列表的循环颤振,for-loop,flutter,For Loop,Flutter,我有一个json,它有一个列表值,我想在gridview.builder下使用这个值, 我试着用一个“for”来表示,只取第一个列表的第一项,然后根据相关索引的长度重复,比如第一个(878878)第二个(878878)等。 我错过了什么 我的目标是在相关卡片旁边获得相关的类型ID(稍后我会将它们命名),但现在看起来是这样的 下面是我的代码和json示例 body: Container( padding: EdgeInsets.all(4),
body: Container(
padding: EdgeInsets.all(4),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: mediaQueryData.orientation == Orientation.portrait ? 1 : 2,
childAspectRatio: mediaQueryData.orientation == Orientation.portrait ? MediaQuery.of(context).size.height/MediaQuery.of(context).size.width/1.05 : MediaQuery.of(context).size.width/(MediaQuery.of(context).size.height-29),
),
itemCount: snapshot.data.results.length,
itemBuilder: (context, index) {
return
Padding(
padding: const EdgeInsets.all(3.0),
child: Container(
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
InkWell(
onTap: (){
setState(() {
firstRun = true;
String tempName;
tempName = _name;
String name = "imdbid=${snapshot.data.results[index].id}&language=${AppLocalizations.of(
context)
.translate(
'lan_code')}@$tempName";
saveNamedPreference(name).then((
bool committed) {Navigator.of(context).pushNamed(
MovieDetailPage.routeName);
});
});
},
child: Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.bottomLeft,
height: 245,
child: Stack(
alignment: Alignment.centerLeft,
children: <Widget>[
Card(
margin: EdgeInsets.only(top: 40),
elevation: 5,
child: Stack(
children: <Widget>[
Container(
padding:EdgeInsets.only(right:10.0),
alignment: Alignment.bottomRight,
child: CircularPercentIndicator(
radius: 40.0,
lineWidth: 5.0,
percent: snapshot.data.results[index].voteAverage/10,
center: Stack(
children: <Widget>[
Text(
snapshot.data.results[index].voteAverage.toString(),
style: TextStyle(
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3
..color = Colors.black,
),
),
new Text(snapshot.data.results[index].voteAverage.toString(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.amber,),),
],
),
progressColor: Colors.amber,
),
),
Container(
padding: mediaQueryData.orientation == Orientation.portrait ? EdgeInsets.only(left:170.0, top: 10) : EdgeInsets.only(left:140.0, top: 10),
alignment: Alignment.topLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("${snapshot.data.results[index].title}",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.black,shadows: [
Shadow(color:Colors.grey,blurRadius: 0,offset: Offset(0,2)),
]),maxLines: 3, textAlign: TextAlign.left,),
Text("(${snapshot.data.results[index].releaseDate.toString().substring(0,4)})",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.black,shadows: [
Shadow(color:Colors.grey,blurRadius: 0,offset: Offset(0,2)),
]),maxLines: 1, textAlign: TextAlign.left),
Container(
width: 150,
height: 120,
child: GridView.builder(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 2/1,),
itemCount: snapshot.data.results[index].genreIds.length,
itemBuilder: (context, index) {
for(var i = 0; i < snapshot.data.results[index].genreIds.length; i++, index++){
print("${snapshot.data.results[index].genreIds.toString()}");
return Text("${snapshot.data.results[index].genreIds.toString()}",);
}
return Container();}),
),
],
),
),
],
),
),
Card(
elevation: 3,
child: Padding(
padding: mediaQueryData.orientation == Orientation.portrait ? const EdgeInsets.all(6.0) : const EdgeInsets.all(4.0),
child: Container(
alignment: Alignment.centerLeft,
width: mediaQueryData.orientation == Orientation.portrait ? 140 : 120,
height: 245,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Image.network(
snapshot.data.results[index].posterPath != null ? "http://image.tmdb.org/t/p/w500/${snapshot
.data.results[index].posterPath}" : "https://i.hizliresim.com/bbn0VB.jpg", fit: BoxFit.contain,),
),
),
),
),
],
),
),
),
],
),
),
);
}
),
),
主体:容器(
填充:边缘设置。全部(4),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
子项:GridView.builder(
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:mediaQueryData.orientation==orientation.portrait?1:2,
childAspectRatio:mediaQueryData.orientation==orientation.Grait?MediaQuery.of(context).size.height/MediaQuery.of(context).size.width/1.05:MediaQuery.of(context).size.width/(MediaQuery.of(context).size.height-29),
),
itemCount:snapshot.data.results.length,
itemBuilder:(上下文,索引){
返回
填充物(
填充:常数边集全部(3.0),
子:容器(
子:堆栈(
对齐:对齐方向.center,
儿童:[
墨水池(
onTap:(){
设置状态(){
firstRun=true;
字符串tempName;
tempName=_name;
String name=“imdbid=${snapshot.data.results[index].id}&language=${AppLocalizations.of(
(上下文)
.翻译(
“lan_code”)}@$tempName”;
SaveNamedReference(名称)。然后((
bool committed){Navigator.of(context.pushName(
MovieDetailPage.routeName);
});
});
},
子:容器(
宽度:MediaQuery.of(context).size.width,
对齐:对齐。左下角,
身高:245,
子:堆栈(
对齐:alignment.centerLeft,
儿童:[
卡片(
页边距:仅限边缘集(顶部:40),
标高:5,
子:堆栈(
儿童:[
容器(
填充:仅限边缘设置(右侧:10.0),
对齐:对齐。右下角,
子:循环指示器(
半径:40.0,
线宽:5.0,
百分比:snapshot.data.results[index].voteAverage/10,
中心:堆栈(
儿童:[
正文(
snapshot.data.results[index].voteAverage.toString(),
样式:TextStyle(
前景:绘画()
…风格=绘画风格笔划
..冲程宽度=3
…颜色=颜色。黑色,
),
),
新文本(snapshot.data.results[index].voteAverage.toString(),
样式:TextStyle(
fontWeight:fontWeight.bold,
颜色:颜色。琥珀色,),),
],
),
progressColor:Colors.amber,
),
),
容器(
padding:mediaQueryData.orientation==orientation.portrait?EdgeInsets.only(左:170.0,顶部:10):EdgeInsets.only(左:140.0,顶部:10),
对齐:alignment.topLeft,
子:列(