У меня тексты и переключатель в ряд, данные хорошие, но раскладка плохая. Я пробовал mainAxisAlignement.spaceAround или mainAxisAlignement.spaceBetween или mainAxisAlignement.spaceEvenly, но список элементов не выровнен зигзагообразно из-за размера текста. Я реализовал следующее введите описание изображения здесь
Виджет заголовка
return Container(
margin: EdgeInsets.only(top: 20),
width: MediaQuery.of(context).size.width,
height: 50,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 5.0,
color: Color.fromRGBO(232, 232, 232, 1),
)),
color: Colors.grey),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Spacer(),
Text("S.N"),
Spacer(),
Text("Food Name"),
Spacer(),
Text("Price"),
Spacer(),
Text("Qty"),
Spacer(),
Text("Action"),
Spacer(),
]),
);
ListItems
return Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(width: 5.0, color: Colors.grey[300])),
color: Colors.white,
),
child: Wrap(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(child: Flexible(child: Text((i + 1).toString()))),
Container(
child: Flexible(
child: Text(
removeAllHtmlTags(menuList[i].name),
softWrap: true,
)),
),
Container(
child: Flexible(
child: Text(
removeAllHtmlTags(menuList[i].discountPrice.toString()),
),
),
),
Container(
child: Flexible(
child: Text(
menuList[i].maxQty.toString(),
),
),
),
Container(
width: 100,
child: menuList[i].status == 0
? Text(
menuList[i].foodStatus,
style: TextStyle(color: Colors.red),
)
: YourListViewItem(
id: menuList[i].id,
index: menuList[i].status,
),
),
],
)
],
));
Виджет YourListViewItem
return ListTile(
trailing: new Switch(
value: isSwitched,
activeColor: Colors.green,
activeTrackColor: Colors.green,
inactiveThumbColor: Colors.white,
inactiveTrackColor: Colors.grey,
onChanged: (value) {
setState(() {
if (isSwitched) {
isSwitched = false;
isSwitched = value;
changeFoodStatus(widget.id);
} else {
isSwitched = true;
isSwitched = value;
changeFoodStatus(widget.id);
}
});
},
),
);