#flutter
#flutter
Вопрос:
Я пытаюсь установить пользовательскую ширину и высоту для дочерних элементов a GridView
. Я попробовал следующее, но это не работает:
GridView.count(
shrinkWrap: true,
crossAxisCount: 5,
children: coolArray.map((String currentItem) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
width: 17,
height: 10,
color: Colors.red,
child: Text('currentItem'),
);
}).toList(),
)
Элементы имеют свою собственную высоту, и я не знаю, как они вычисляются.
Ответ №1:
Вы можете использовать дочерний параметр, например
GridView.count(
shrinkWrap: true,
crossAxisCount: 5,
childAspectRatio:width/height,
children: coolArray.map((String currentItem) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
color: Colors.red,
child: Text('currentItem'),
);
}).toList());
Комментарии:
1. Как я могу получить crossAxisCount для автоматической компоновки на основе ширины экрана?