0

我正在制作一个测验应用程序,但选项采用列表格式。但我想要网格视图中的选项。

...(_questions[_questionIndex]['answers']
                as List<Map<String, Object>>)
            .map(
          (answer) => Answer(
            answerText: answer['answerText'],
            answerColor: answerWasSelected
                ? answer['score']
                    ? Colors.green
                    : Colors.red
                : null,
            answerTap: () {
              // if answer was already selected then nothing happens onTap
              if (answerWasSelected) {
                return;
              }

我的选项采用这种格式: 当前选项格式

但我希望它们采用 2*2 格式(2 行和两列)。

4

1 回答 1

0

Something like this

 GridView.builder(
  itemCount: data.length,`// length of the list
  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 2 ),
  itemBuilder: (BuildContext context, int index) {
    return new Card(
      child: new GridTile(
        footer: new Text(data[index]['name']),
        child: new Text(data[index]
            ['image']),
      ),
    );
  },
),
于 2021-12-18T10:24:06.030 回答