Gaurav Kumar
Gaurav Kumar

Reputation: 41

How to change format from list view to grid view in flutter?

I am making an quiz app but option are in list format. But I want the option in grid view.

...(_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;
              }

My option are in this format: Current option format

But I want them in 2*2 format ( 2 row and two columns).

Upvotes: 0

Views: 163

Answers (1)

Aderoju Israel
Aderoju Israel

Reputation: 154

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']),
      ),
    );
  },
),

Upvotes: 0

Related Questions