[英]How to change Containers with round Corners edge background
I am trying to match the color in the rectangle with the color above it. 我正在尝试将矩形中的颜色与其上方的颜色匹配。
I have tried to use Cards and ClipRRect both produce the same problem. 我试图使用Cards和ClipRRect都产生相同的问题。
Column(
children: <Widget>[
Expanded(
child: Container(),
),
Expanded(
child: Container(
child: Text(
'data ',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
),
),
Expanded(
child: Container(
child: Text(
'data',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
),
)
],
)
The color inside the rectangle should be the same as the color above it 矩形内的颜色应与其上方的颜色相同
This is one way of doing it. 这是一种方法。
Column(
children: <Widget>[
Expanded(
child: Container(),
),
Expanded(
child: Container(
child: Text(
'data ',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
),
),
Expanded(
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
color: Colors.blue,
),
Container(
alignment: Alignment.topCenter,
child: Text(
'data',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
),
],
),
)
],
)
This sounds like a good candidate for a Stack
这听起来像是
Stack
的不错候选人
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(
top: 50, // Top margin per card
child: Container(
child: Text(
'data ',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
)),
Positioned.fill(
top: 250,
child: Container(
child: Text(
'data ',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.center,
),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80),
),
),
)),
],
);
}
This would prevent you from having to match the colour of your Container
with the card you happen to be showing the new card in front of. 这样可以避免您将
Container
的颜色与恰好在其前面显示新卡片的卡片相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.