如何从ListView进行PageView的特定元素?

时间:2019-05-28 06:07:33

标签: list flutter flutter-layout

我正在开发我的第一个Flutter应用程序。我卡在PageView中。实际上,我从API中获得问题和选项的列表,并在具有选项的PageView中显示所有问题。有3个按钮,第一个是“上一个”,第二个是“评论”,第三个是“下一个”。当用户按“上一个”时,如果不是第一个,则用户将继续前一个问题;当用户按“下一个”时,用户将继续下一个问题;当用户单击“复查”时,用户将看到尝试过该问题的列表。不是。

我需要两件事:

  1. 当用户单击另一个答案后将继续另一个问题时 问题,然后用户将再次回答该问题 应该在那里。(答案正在广播中显示)

  2. 当用户进入“审阅”屏幕时,将列出一些问题 尝试与否,我想要当用户单击列表中的某个元素时,用户将 继续点击同一问题。

这是Listview:

Container(
            child: ListView.builder(
                itemCount: data == null ? 0 : data.length,
                padding: const EdgeInsets.all(15.0),
                itemBuilder: (context, position) {
                  return Column(
                    children: <Widget>[
                      ListTile(
                          contentPadding: EdgeInsets.all(15.0),
                          leading: Text(
                            '${data[position]["state"]}',
                            style: TextStyle(
                              fontSize: 22.0,
                              color: Colors.deepOrangeAccent,
                            ),
                          ),
                          title: Column(
                            children: <Widget>[
                              CircleAvatar(
                                backgroundColor: Colors.blueAccent,
                                radius: 40.0,
                                child:'${data[position]["state"]}' != "True" ? Text("Not Attemted",style: TextStyle(
                                  fontSize: 18.0,
                                  color: Colors.white,
                                ),) : Text(
                                  'Attempted',
                                  style: TextStyle(
                                    fontSize: 18.0,
                                    color: Colors.white,
                                  ),
                                ),
                              )
                            ],
                          ),
                          onTap: () {}
                      )
                    ],
                  );
                }),
             )

这是电台: 计数器值仅用于检查用户选择哪个选项并应答发送以按“下一步”计数器值。


String counter = "0000";

  int radioValue = 0;
  int ans1Value = 1;
  int ans2Value = 2;
  int ans3Value = 3;
  int ans4Value = 4;


  void handleRadioValueChanged(int value) {
    setState(() {
      radioValue = value;
      switch (radioValue) {
        case 1:
          counter="1000";
          break;
        case 2:
          counter="0100";
          break;
        case 3:
          counter="0010";
          break;
        case 4:
          counter="0001";
          break;
      }
    });
  }






Expanded(
                        flex: 2,
                        child:new Container(
                            child: new SingleChildScrollView(
                              child: new Row(
                                children: <Widget>[
                                  new Padding(padding: EdgeInsets.all(20.0)),
                                  new Flexible(
                                    child: new Text('${questions[position]["question"]}',
                                      style: TextStyle(color: Colors.black87,
                                      fontSize: 20.0,fontWeight: FontWeight.bold,
                                    ),textAlign: TextAlign.start,),
                                    flex: 1,
                                  ),
                                ],
                              ),
                            ),
                          color: Colors.greenAccent,
                        )
                    ),
                    Expanded(
                      flex: 3,
                      child: new Container(
                        child: new SingleChildScrollView(
                          child: new Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: <Widget>[
                              new Padding(padding: EdgeInsets.all(5)),
                              new Row(
                                children: <Widget>[
                                  new Radio(value: ans1Value,groupValue: radioValue, onChanged: handleRadioValueChanged),
                                  new Text(
                                    '${questions[position]["op1"]}',
                                    style: new TextStyle(fontSize: 16.0),
                                  ),
                                ],
                              ),
                              new Padding(padding: EdgeInsets.all(5)),
                              new Row(
                                children: <Widget>[
                                  new Radio(
                                    value: ans2Value,
                                    groupValue: radioValue,
                                    onChanged: handleRadioValueChanged,
                                  ),
                                  new Text(
                                    '${questions[position]["op2"]}',
                                    style: new TextStyle(
                                      fontSize: 16.0,
                                    ),
                                  ),
                                ],
                              ),
                              new Padding(padding: EdgeInsets.all(5)),
                              new Row(
                                children: <Widget>[
                                  new Radio(value: ans3Value,groupValue: radioValue, onChanged: handleRadioValueChanged),
                                  new Text(
                                    '${questions[position]["op3"]}',
                                    style: new TextStyle(fontSize: 16.0),
                                  ),
                                ],
                              ),
                              new Padding(padding: EdgeInsets.all(5)),
                              new Row(
                                children: <Widget>[
                                  new Radio(
                                    value: ans4Value,
                                    groupValue: radioValue,
                                    onChanged: handleRadioValueChanged,
                                  ),
                                  new Text(
                                    '${questions[position]["op4"]}',
                                    style: new TextStyle(
                                      fontSize: 16.0,
                                    ),
                                  ),
                                ],
                              ),
                              new Padding(padding: EdgeInsets.all(5)),
                            ],
                          ),
                        ),
                      )
                    ),

0 个答案:

没有答案