居中图像和文本 列内部 容器内部
Center Image and Text Inside of Column Inside of Container
我已经尝试了很多方法,但我无法让我的图像和文本(列)在我的容器内居中。它停留在容器的顶部。这是我的设置:
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//Container 1
Container(
height: 150,
width: 150,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.green, width: 3),
borderRadius: BorderRadius.all(Radius.circular(18)),
),
child: Column(
children: const [
Expanded(
child: Image(
image: AssetImage('assets/images/Church.png'),
),
),
Expanded(
child: Text(
'Our Church',
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontFamily: 'DMSans',
fontWeight: FontWeight.w500,
),
),
),
],
)),
这是屏幕上的结果图像:
首先删除两个 Expanded
小部件,然后将 MainAxisAlignment
应用到 center
。
您的代码应如下所示:
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 150,
width: 150,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.green, width: 3),
borderRadius: const BorderRadius.all(Radius.circular(18)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Image.asset(
'assets/Avatar.png',
width: 60,
height: 40,
),
Text(
'Our Church',
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontFamily: 'DMSans',
fontWeight: FontWeight.w500,
),
),
],
),
),
],
);
}
编辑:我没有教堂图片,抱歉更换。
我已经尝试了很多方法,但我无法让我的图像和文本(列)在我的容器内居中。它停留在容器的顶部。这是我的设置:
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//Container 1
Container(
height: 150,
width: 150,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.green, width: 3),
borderRadius: BorderRadius.all(Radius.circular(18)),
),
child: Column(
children: const [
Expanded(
child: Image(
image: AssetImage('assets/images/Church.png'),
),
),
Expanded(
child: Text(
'Our Church',
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontFamily: 'DMSans',
fontWeight: FontWeight.w500,
),
),
),
],
)),
这是屏幕上的结果图像:
首先删除两个 Expanded
小部件,然后将 MainAxisAlignment
应用到 center
。
您的代码应如下所示:
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 150,
width: 150,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.green, width: 3),
borderRadius: const BorderRadius.all(Radius.circular(18)),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Image.asset(
'assets/Avatar.png',
width: 60,
height: 40,
),
Text(
'Our Church',
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontFamily: 'DMSans',
fontWeight: FontWeight.w500,
),
),
],
),
),
],
);
}
编辑:我没有教堂图片,抱歉更换。