I am writing a game in Flutter.
I have a List that stores a random number of objects - grocery items.
They need to be generated on the screen in a row, as if they were on a conveyor belt. They will move at the same speed, then disappear in turn.
Main problem: How to generate widgets on the screen? There are many tips for making a dynamic list, but this is not a list. These widgets are self-contained.
class GenerateProductList {
static List getProductList() {
ProductList.add(new Product());
ProductList.add(new Product());
ProductList.add(new Product());
return ProductList;
}
}
// Product object. It might be better to make it a widget.
class Product {
String name = 'Water';
int price = 2;
Widget icon = new Image.asset('assets/images/Water.png');
int position;
int discount;
}
There is no point in showing the main code, it is almost empty. I'm still learning, don't judge me
question from:
https://stackoverflow.com/questions/66050466/flutter-dynamic-widget-creation-doesnt-list 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…