[英]positioned widget work but align widget don't work in stack widget in flutter
Why when I try to use align in stack with alignment his child don't move , but with positioned it's work (I want use it because I can't center it in all mobile dimension) 为什么当我尝试在堆栈中使用align时,他的孩子不动,但定位后就行了(我想使用它,因为我无法在所有移动尺寸中居中)
This is my code: 这是我的代码:
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _launchURL,
child: Container(
child: Container(
child: Stack(children: <Widget>[
Column(
children: <Widget>[
Container(
decoration: new BoxDecoration(
border: Border.all(color: Colors.black12),
borderRadius: BorderRadius.all(Radius.circular(13)),
shape: BoxShape.rectangle,
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black26,
offset: Offset(3, 7),
blurRadius: 7.0,
),
],
),
height: 140,
width: MediaQuery.of(context).size.width * 0.42,
),
],
),
// this the code when I use the align widget
// Align(
// alignment: Alignment.bottomCenter,
Positioned(
top: MediaQuery.of(context).size.width * 0.42 / 7,
left: 40,
child: Container(
child: Column(
children: <Widget>[
Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
shape: BoxShape.rectangle,
color: Colors.transparent,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(2, 5),
blurRadius: 5.0,
),
],
),
child: ClipRRect(
borderRadius: new BorderRadius.circular(16.0),
child: Image.asset(
"assets/RoundStyle/" + socialBadge + ".png",
height: 60,
width: 60,
),
),
),
SizedBox(
height: 20,
),
MyText3(
"@hisname",
color: Colors.grey,
)
],
),
),
),
]),
),
),
);
}
That's it thank you :) 就是这样,谢谢:)
You don't need a Stack
or Column
if you want to center your widget inside the Container
just add it as a child
. 如果您想将小部件放在
Container
内部居中,则不需要Stack
或Column
,只需将其添加为child
Container
即可。
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _launchURL,
child: Container(
decoration: new BoxDecoration(
border: Border.all(color: Colors.black12),
borderRadius: BorderRadius.all(Radius.circular(13)),
shape: BoxShape.rectangle,
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black26,
offset: Offset(3, 7),
blurRadius: 7.0,
),
],
),
height: 140,
width: MediaQuery.of(context).size.width * 0.42,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
shape: BoxShape.rectangle,
color: Colors.transparent,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(2, 5),
blurRadius: 5.0,
),
],
),
child: ClipRRect(
borderRadius: new BorderRadius.circular(16.0),
child: Image.asset(
"assets/RoundStyle/" + socialBadge + ".png",
height: 60,
width: 60,
),
),
),
SizedBox(
height: 20,
),
MyText3(
"@BensebaBillal",
color: Colors.grey,
)
],
),
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.