为什么我的中心小部件在 Dart 中不起作用? |扑
Why my Center widget doesn't work in Dart? | Flutter
我正在尝试将所有小部件(2 个图标和文本)居中,但是当我添加中心小部件时(在 child 之前:我放置 child 的行:中心(下面的代码)),没有任何反应,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,
),
],
),
我正在尝试将所有小部件(2 个图标和文本)居中,但是当我添加中心小部件时(在 child 之前:我放置 child 的行:中心(下面的代码)),没有任何反应,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,
),
],
),