我是Flutter应用程序开发的新蜂。我正在开发Flutter应用程序。我的问题是,每当我由应用程序运行的ListView.builder()未被执行并且FutureBuilder()一次又一次地重建时,就像所有条件变为真并无限地执行一样,我已经尝试了许多方法,例如ListView.custom并且切换大小写,而不是每次我都得到相同结果时,是否可以解决此问题?
注意:我正在从Restful API中获取数据。
@override
Widget build(BuildContext context) {
return ResponsiveBuilder(
builder: (context,sizingInformation){
return SafeArea(
child: Scaffold(
body: FutureBuilder(
future: GalleryInformation().getGalleryList(widget.id),
builder:(BuildContext context,AsyncSnapshot snapshot){
if(snapshot.hasError){
return Container();
}
else if(snapshot.connectionState == ConnectionState.done){
var response = snapshot.data as List<Gallery>;
return ListView.builder(
itemCount: response.length,
itemBuilder: (context,index){
print(widget.id);
var gallery = response[index];
return Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: sizingInformation.localWidgetSize.height*0.5,
width: sizingInformation.localWidgetSize.width,
child: Image(
image: AssetImage(liberationWarImage),
fit: BoxFit.fill,
)
),
Positioned(
top: sizingInformation.localWidgetSize.height*.41,
child: Container(
height: sizingInformation.localWidgetSize.height*.10,
width: sizingInformation.localWidgetSize.width,
padding: EdgeInsets.only(left:10,right: 10 ),
child: Card(
elevation: 5,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left:8.0),
child: Text("Liberation",
style: TextStyle(
fontSize:18,
fontWeight: FontWeight.bold
),
),
),
Container(
padding: EdgeInsets.only(right:8.0),
child: FlatButton(onPressed:(){},
child: Text("More"),
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.black
)
),
),
)
],
),
),
),
)
],
),
Expanded(
child: Container(
padding: EdgeInsets.only(top:20),
height: sizingInformation.localWidgetSize.height,
child:
ListView(
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(left:10,right:10 ),
children: <Widget>[
Column(
children: <Widget>[
Card(
child: Container(
height: 80,
width: sizingInformation.localWidgetSize.width,
child: Row(
children:[
Container(
height:300,
width:sizingInformation.localWidgetSize.width*.25,
child: Image(
image: NetworkImage(gallery.image),
fit: BoxFit.fill,
),
),
Container(
padding: EdgeInsets.only(left:10),
child:Column(
children:[
Text(gallery.title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize:18
),)
]
)
)
]
),
),
),
],
)
// Wrap(
// children: <Widget>[
// Container(
// padding: EdgeInsets.only(left:10),
// child:Text("",
// style: TextStyle(
// fontSize: 16,
// ),
// )
// ),
// ],
// ),
],
),
),
)
],
);
},
);
}
else{
return CircularProgressIndicator();
}
})