flutter - 定位小部件工作但对齐小部件在颤动的堆栈小部件中不起作用
问题描述
为什么当我尝试在堆栈中使用对齐对齐时,他的孩子不会移动,但定位它是工作(我想使用它,因为我不能在所有移动维度中居中)
这是我的代码:
@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,
)
],
),
),
),
]),
),
),
);
}
就是这样谢谢你:)
解决方案
您不需要 a Stack
,或者Column
如果您想将小部件居中,Container
只需将其添加为child
.
@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,
)
],
),
),
);
}
推荐阅读
- python-3.x - 使用 TfidfVectorizer 的词频
- sql - 两个表的联合选择 * 但仅在某些列中没有重复项的情况下
- rsync - rsync --exclude 不排除第一个值
- c# - DynamoDB 查询不返回所有属性
- angular - 如何在 Angular 6+ 中为库级接口的应用程序级具体实现定义可摇树的提供程序?
- python - 如果它们包含给定的短语,则删除python中字符串列表的所有元素
- sql - 使用带有窗口函数的递归 CTE
- makefile - 传递要在 MAKEFLAGS 中扩展的变量
- rust - 如何在 Rust 中开发词典?
- google-apps-script - 无法在电子表格上创建可安装触发器