简体   繁体   English

如何将数字(通过单击按钮“OnPressed 属性”)从 stful 小部件(应用程序的第一个屏幕)传递到第二页的 ListView.builder

[英]How to pass a number (through clicking Button "OnPressed property) from a stful widget (First screen on the app) to ListView.builder at Second Page

I got an issue.我有一个问题。 I am at the opening page of my app, which is stful widget.我在我的应用程序的打开页面,这是一个 stful 小部件。 In the middle of the screen is a button, and a container below.屏幕中间是一个按钮,下面是一个容器。 In the container appears random numbers every some time.在容器中每隔一段时间就会出现随机数。 How can I solve the problem, where I want to create ListView.builder at the Second Page, which is also stful widget.我该如何解决这个问题,我想在第二页创建 ListView.builder,这也是 stful 小部件。 I need him to be stful.我需要他保持冷静。 I want to create ListView according to the numbers at the first page, by clicking the button and sending data to the Listview.builder.我想根据第一页的数字创建 ListView,方法是单击按钮并将数据发送到 Listview.builder。 I need a simple solution how to manage this case.我需要一个简单的解决方案来管理这种情况。 All my trails failed.我所有的足迹都失败了。 It would be fantastic for a help!能得到帮助真是太棒了!

as I understand you should keep one int array and set random numbers into the array, then on the second page, you need a constructor to take data, then in init state set them.据我了解,您应该保留一个 int 数组并将随机数设置到数组中,然后在第二页上,您需要一个构造函数来获取数据,然后在 init state 中设置它们。 The second page should be as below example.第二页应如下例所示。

class SecondPage extends StatefulWidget {
  final List<int> data;

  SecondPage(this.data);



 @override
  _SecondPageState createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage> {
  List<int> _list = List<int>();

  @override
  void initState() {
    _list = widget.data;
    super.initState();
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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