0

When I build my page I want my dayTile widgets to be in a row of 2. I don't know how many the user will desire so I need to use a listView.Builder. The problem I am facing is that the way I am building only works when the array has an even number of items.

            ListView.builder(
              itemCount: dayTiles.length,
              itemBuilder: ((context, index) {
                return index.isEven
                    ? Row(
                        children: [
                          dayTiles[index],
                          dayTiles?[index + 1] ?? Container(),
                        ],
                      )
                    : Container();
              }),
            ),

How would I make this return a row with only one dayTile in it, with the other space empty?

The image below contains the desired effect. enter image description here

1 Answer 1

0

Based on your UI, you can use GridView.builder instead of ListView.

GridView.builder(
  gridDelegate:
      SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
  itemBuilder: (context, index) => dayTiles[index],
);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.