【发布时间】:2019-12-23 01:15:26
【问题描述】:
我想让我的文本在 Stack 小部件内居中。这是我迄今为止所尝试的。现在,它位于图像顶部的左侧,这不是我想要的位置。我试过使用Align 小部件和Center 小部件,但无济于事。我做错了什么?
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 8,top: 8,bottom: 8,right: 8),
child: Stack(
children: <Widget>[
Wrap(
children: <Widget>[
Image.network("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR1OlcL_Laxy1rcct4vok3rkEb3l6NdV1pncE1_K1mzZ9NDYy3J",
height: 100,
),
],
),
Container(
width: MediaQuery.of(context).size.width/2,
height: 100,
child: Center(
child: Wrap(
children: <Widget>[
Center(
child: Container(
height: 100,
width: MediaQuery.of(context).size.width/2,
child: Align(
alignment: Alignment.center,
child: Text(
"BOOKS AND BOOKLETS",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
),
],
),
),
),
Expanded(child: Card(
child: Container(
child: Center(
child: Stack(
children: <Widget>[
Image.network("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR1OlcL_Laxy1rcct4vok3rkEb3l6NdV1pncE1_K1mzZ9NDYy3J",
height: 100,
),
SafeArea(child: Text("asdad"))
],
),
),
),
))
如果文本大小过小(表示“abc”),则识别出问题,但如果文本大小过大(表示“abc abc abc acb acb abc”),则无法正常工作
如何解决这个问题?
【问题讨论】:
-
我们可以看到整个代码,也就是在灵活小部件上方吗?
-
另外,您可以使用
EdgeInsets.all(8)而不是单独指定所有这些。