Flutter 如何在颤振中将一个容器夹在另一个容器上?
我想建立一个可重用的卡片小部件,它将有一些自定义设计布局的图像和文本。我尽了我所能,但没能达到预期的效果。任何帮助都将不胜感激。Flutter 如何在颤振中将一个容器夹在另一个容器上?,flutter,user-interface,containers,flutter-layout,flutter-dependencies,Flutter,User Interface,Containers,Flutter Layout,Flutter Dependencies,我想建立一个可重用的卡片小部件,它将有一些自定义设计布局的图像和文本。我尽了我所能,但没能达到预期的效果。任何帮助都将不胜感激。 使用ClipRRect执行此操作: ClipRRect( borderRadius: BorderRadius.circular(50.0), //clipping the whole widget child: Container( height: MediaQuery.of(context).size.height * 0.4, //I adj
使用
ClipRRect
执行此操作:
ClipRRect(
borderRadius: BorderRadius.circular(50.0), //clipping the whole widget
child: Container(
height: MediaQuery.of(context).size.height * 0.4, //I adjusted here for responsiveness problems on my device
width: MediaQuery.of(context).size.width * 0.5,
color: Colors.white,
child: LayoutBuilder(
builder: (context, constraint) {
return Stack(
children: [
Center(
child: Icon(
Icons.trip_origin,
size: constraint.biggest.width,
color: Colors.grey[300],
),
),
Positioned(
right: 0,
left: 0,
top: 20.0,
child: Icon(
Icons.sports_volleyball_rounded, //just to represent the ball
size: constraint.biggest.width * 0.5,
),
),
Positioned(
bottom: 0.0,
child: Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height * 0.1,
width: constraint.biggest.width,
color: Colors.yellow[700],
child: Text(
'Sports',
style: Theme.of(context)
.textTheme
.headline3
.copyWith(color: Colors.white),
),
),
),
],
);
},
),
),
);
使用
ClipRRect
执行此操作:
ClipRRect(
borderRadius: BorderRadius.circular(50.0), //clipping the whole widget
child: Container(
height: MediaQuery.of(context).size.height * 0.4, //I adjusted here for responsiveness problems on my device
width: MediaQuery.of(context).size.width * 0.5,
color: Colors.white,
child: LayoutBuilder(
builder: (context, constraint) {
return Stack(
children: [
Center(
child: Icon(
Icons.trip_origin,
size: constraint.biggest.width,
color: Colors.grey[300],
),
),
Positioned(
right: 0,
left: 0,
top: 20.0,
child: Icon(
Icons.sports_volleyball_rounded, //just to represent the ball
size: constraint.biggest.width * 0.5,
),
),
Positioned(
bottom: 0.0,
child: Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height * 0.1,
width: constraint.biggest.width,
color: Colors.yellow[700],
child: Text(
'Sports',
style: Theme.of(context)
.textTheme
.headline3
.copyWith(color: Colors.white),
),
),
),
],
);
},
),
),
);
很高兴我能帮忙!很高兴我能帮忙!