我正在尝试居中所有小部件(2个图标和文本(,但当我添加居中小部件时(在child:row之前,我放置child:Center(下面的代码((,什么都没发生,0个错误,只是不起作用。
Container(
width: 100.0,
height: 100.0,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: const Icon(
Icons.outbond_outlined,
color: Colors.amber,
size: 50.0,
),
),
Container(
width: 220.0,
height: 100.0,
decoration: const BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Row(
// ignore: prefer_const_literals_to_create_immutables
children: [
const Icon(
Icons.call_end_sharp,
color: Colors.amber,
size: 30.0,
),
const Text(
"Skrt",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
fontFamily: "Lato"),
),
const Icon(
Icons.call_end_sharp,
color: Colors.amber,
size: 30.0,
),
],
),
),
在您的行中使用mainAxisAlignment:mainAxisAlignment。center
示例:
Row(
// ignore: prefer_const_literals_to_create_immutables
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.call_end_sharp,
color: Colors.amber,
size: 30.0,
),
const Text(
"Skrt",
style: TextStyle(
color: Colors.black,
fontSize: 30.0,
fontFamily: "Lato"),
),
const Icon(
Icons.call_end_sharp,
color: Colors.amber,
size: 30.0,
),
],
),