Complete the code to create a GridView with 4 columns.
GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: [1]), itemCount: 8, itemBuilder: (context, index) { return Container(color: Colors.blue); }, )
The crossAxisCount property sets the number of columns in the grid. Here, 4 columns are needed.
Complete the code to set the number of items in the grid to 10.
GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), itemCount: [1], itemBuilder: (context, index) { return Container(color: Colors.red); }, )
itemCount to a wrong number.itemCount.The itemCount property sets how many items the grid will show. Here, it should be 10.
Fix the error in the code by completing the missing property to create a grid with fixed cross axis count.
GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount([1]: 2), itemCount: 6, itemBuilder: (context, index) { return Container(color: Colors.green); }, )
mainAxisCount which does not exist.The property crossAxisCount defines how many columns the grid has. This is required for SliverGridDelegateWithFixedCrossAxisCount.
Fill both blanks to create a grid with 3 columns and spacing of 10 pixels between items.
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: [1],
crossAxisSpacing: [2],
),
itemCount: 9,
itemBuilder: (context, index) {
return Container(color: Colors.orange);
},
)crossAxisCount sets the number of columns, here 3. crossAxisSpacing sets the space between columns, here 10 pixels.
Fill all three blanks to create a grid where keys are uppercase strings, values are colors, and only items with index greater than 3 are included.
final Map<String, Color> colorMap = {
for (var i = 0; i < 7; i++)
if (i [3] 3) [1]: [2],
};The key is the uppercase string of the index: i.toString().toUpperCase(). The value is a color, here Colors.blue. The condition filters items with index greater than 3 using >.