looking directly at the code, setstate will always call the listview.builder method indefinitely. It seems to loop infinitely all the time
import "package:flutter/material.dart";
import "package:http/http.dart" as http;
import "dart:convert";
import "package:video/AppConfig.dart";
class Home extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return HomeState();
}
}
class HomeState extends State<Home> {
double _width = 0.0;
Widget build(BuildContext context) {
this._width = MediaQuery.of(context).size.width;
print(this._width);
return new Scaffold(
appBar: new AppBar(
title: new Text("")
),
body: new ListDislay(),
);
}
}
//
class ListDislay extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return ListDisplayState();
}
}
class ListDisplayState extends State<ListDislay>{
List _card = new List();
double _width = 0.0;
Widget build(BuildContext context){
this._width = MediaQuery.of(context).size.width;
this.getList();
return new Scaffold(
body:new ListView.builder(
itemCount: _card.length,
itemBuilder: (context,i){
// return _card[i];
print(":"+this._card.length.toString());
return new GestureDetector(
child: _card[i],
onTap: (){
print(""+i.toString());
},
);
},
) ,
);
}
getList() async{
var url = AppConfig.base + "/api/new_list";
//URLGET
http.get(url).then((response) {
var data = json.decode(response.body);
var _TempCard = [];
data.forEach((v){
print(v);
_TempCard.add(new Card(
child: new Flex(
direction: Axis.vertical,
children: <Widget>[
new Image.network(
AppConfig.base + "/file/"+v["Id"]+"/1.jpg",
fit: BoxFit.fill,
width: this._width,
height: 200.0,
// width: new Width,
),
new Text(v["Originalname"])
],
),
));
});
//.?
setState(() {
this._card = _TempCard;
});
});
}
}