Reputation: 407
I want to use loop in Flutter so that whenever i call this class it's code get executed multiple times. please solve any error in this code or please give me another method that gives same output
class tryy extends StateLessWidget{
@override
Widget build(BuildContext Context){
var i = 1;
while(i<=5){
i = i+1;
return Text("hey")
}
}
}
Upvotes: 1
Views: 4430
Reputation: 1082
You don't have to create a whole class for that, simply you can create a method that retruns a list of widgets and you can use that result in Row or Column ...
List<Widget> repeatWiget(Widget widget, int times){
List<Widget> res = List();
for(int i = 0; i < times; i++){
res.add(widget);
}
return res;
}
and you can use that for example like this:
Column(children:repeatWiget(Text("repeat me 5 times"), 5)
Upvotes: 2