Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

Flutter. Dynamic widget creation doesn't list

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...