简体   繁体   中英

How to make ListView.builder build only 1 widget per second?

Is it possible to make ListView.builder build only 1 widget per second?

Tried to use Future.delayed() and sleep() but its just don't do anything.

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView.builder(
        itemCount: 20,
        itemBuilder: (context, index) {
          Future.delayed(
            const Duration(seconds: 1),
          );
          return Text(index.toString());
        },
      ),
    );
  }

Thanks in advance

Create a list and add items to the list using a timer

List<String> allWidget = [];
@override
 void initState(){
  startTimer();
}
@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView.builder(
        itemCount: allWidget.length,
        itemBuilder: (context, index) {
          return Text(allWidget[index].toString());
        },
      ),
    );
  }
startTimer(){
   Timer.periodic(Duration(seconds: 1), (timer){
      if(allWidget.length >= 20) {
        timer.cancel();
      } else{ 
        allWidget.addd("${allWidget.length}");
        setState((){});
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM