使用Flutter RadioListTile的多项选择Qns测试应用

时间:2019-11-20 14:31:18

标签: flutter dart

在我的测试应用中,我有3或4个选项供您选择。因此,如下所示,我将选项放入选项中(在一个类中),但是如何调用RadioListTile?因为选择位于二维数组中。

poly_t

1 个答案:

答案 0 :(得分:0)

尝试这样,希望对您有所帮助

String _selection = '';

  List<List<String>> choices = [
    ["ABC", "AAB", "ACD"], // 1st qns has 3 choices
    ["AND", "CQA", "QWE", "QAL"], // 2nd qns has 4 choices
    ["ASD", "JUS", "JSB"] // 3rd qns has 3 choices
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text('Question here?'),
          Column(
            children: choices[0].map((item) { //change index of choices array as you need
              return RadioListTile(
                groupValue: _selection,
                title: Text(item),
                value: item,
                activeColor: Colors.blue,
                onChanged: (val) {
                  print(val);
                  setState(() {
                    _selection = val;
                  });
                },
              );
            }).toList(),
          )
        ],
      ),
    );
  }