Flutter 颤振:在堆栈小部件中删除图像顶部
我正在尝试在我的小部件树中使用堆栈:Flutter 颤振:在堆栈小部件中删除图像顶部,flutter,flutter-layout,Flutter,Flutter Layout,我正在尝试在我的小部件树中使用堆栈: body: Center( child: SingleChildScrollView( child: Stack( overflow: Overflow.visible, children: <Widget>[ Container( // card view alignment: Alignment.center,
body: Center(
child: SingleChildScrollView(
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Container(
// card view
alignment: Alignment.center,
height: 200,
margin: EdgeInsets.only(
top: 20.0, bottom: 50.0, left: 50.0, right: 50.0),
decoration: BoxDecoration(
color: color_transparent_black,
borderRadius: BorderRadius.circular(14.0),
),
),
Positioned(
top: -60,
left: 0,
right: 0,
bottom: 0,
child: Align(
alignment: Alignment.topCenter,
child: Container(
width: width * 0.3,
height: height * 0.2,
child: CircleAvatar(
backgroundColor: Colors.transparent,
child: Image.asset("assets/images/ic_setting.png"),
),
),
),
),
],
),
),
),
);
主体:中心(
子:SingleChildScrollView(
子:堆栈(
溢出:溢出。可见,
儿童:[
容器(
//卡片视图
对齐:对齐.center,
身高:200,
页边距:仅限边距(
顶部:20.0,底部:50.0,左侧:50.0,右侧:50.0),
装饰:盒子装饰(
颜色:颜色\透明\黑色,
边界半径:边界半径。圆形(14.0),
),
),
定位(
前-60,
左:0,,
右:0,,
底部:0,
子对象:对齐(
对齐:alignment.topCenter,
子:容器(
宽度:宽度*0.3,
高度:高度*0.2,
孩子:圆环星(
背景颜色:颜色。透明,
子项:Image.asset(“assets/images/ic_setting.png”),
),
),
),
),
],
),
),
),
);
这个结果是这样的:
为什么删除了设置顶部图标?很可能是因为您为定位的
小部件设置了顶部:-60
编辑1:
通过删除SingleChildScrollView
您可以使用Stack
小部件本身的alignment:alignment.topCenter
属性将Stack
的所有子级居中
child: Center(
child: Stack(
overflow: Overflow.visible,
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 200,
...
),
Positioned(
top: -60,
...
child: Container(
...
),
),
),
]),
child:Center(
子:堆栈(
溢出:溢出。可见,
对齐:alignment.topCenter,
儿童:[
容器(
身高:200,
...
),
定位(
前-60,
...
子:容器(
...
),
),
),
]),
我解决了这个问题:
body: Center(
child: SingleChildScrollView(
child: Stack(
// overflow: Overflow.visible,
children: <Widget>[
Container(
// card view
alignment: Alignment.center,
height: 200,
margin: EdgeInsets.only(
top: 80.0, bottom: 50.0, left: 50.0, right: 50.0),
decoration: BoxDecoration(
color: color_transparent_black,
borderRadius: BorderRadius.circular(14.0),
),
),
FractionalTranslation(
translation: Offset(0.0, 0.0),
child: Align(
alignment: Alignment.topCenter,
child: Container(
width: width * 0.3,
height: height * 0.2,
child: CircleAvatar(
backgroundColor: Colors.transparent,
child: Image.asset("assets/images/ic_setting.png"),
),
),
),
),
],
),
),
),
);
主体:中心(
子:SingleChildScrollView(
子:堆栈(
//溢出:溢出。可见,
儿童:[
容器(
//卡片视图
对齐:对齐.center,
身高:200,
页边距:仅限边距(
顶部:80.0,底部:50.0,左侧:50.0,右侧:50.0),
装饰:盒子装饰(
颜色:颜色\透明\黑色,
边界半径:边界半径。圆形(14.0),
),
),
分馏翻译(
平移:偏移量(0.0,0.0),
子对象:对齐(
对齐:alignment.topCenter,
子:容器(
宽度:宽度*0.3,
高度:高度*0.2,
孩子:圆环星(
背景颜色:颜色。透明,
子项:Image.asset(“assets/images/ic_setting.png”),
),
),
),
),
],
),
),
),
);
结果是:
I将顶部边距增加到顶部:80.0
,并用分馏翻译替换定位的。实际上,它也与定位的
一起工作 我希望照片高于容器@AlanCI尝试删除SingleChildScrollView
,它不再剪辑图像。