Flutter listview is always added indefinitely when it changes its state.

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;
      });
    });

  }
}
Jul.21,2021

you call load getList, during build. After loading, calling setState, equals calling build,. This is an infinite loop. GetList should be called in initState, but cannot be transferred in build.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5ae83-455d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5ae83-455d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?