[英]How to make a transparent container stand out from the background?
I'm trying to make my containers transparent and still want them to easily standout from the background color, just like below image.我正在尝试使我的容器透明,并且仍然希望它们能够轻松地从背景颜色中脱颖而出,就像下图一样。 (this is PSD image)
(这是PSD图像)
I tried wrapping Container
inside a Material
widget like this:我尝试将
Container
包装在Material
小部件中,如下所示:
class customBar extends StatelessWidget {
const customBar({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
elevation: 2,
borderRadius: BorderRadius.circular(10),
child: Container(
width: double.infinity,
height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
//color: Color(0xff0a4873),
),
child: Text(
'',
textAlign: TextAlign.left,
),
),
);
}
}
but it gives it too much elevation
但它给了它太多的
elevation
also tried using a solid color but that doesn't give me what is required either,也尝试使用纯色,但这也不能满足我的要求,
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
customBar(),
Container(
width: double.infinity,
height: 60,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Color(0xff0a4873),
),
child: Text(
'',
textAlign: TextAlign.left,
),
),
],
),
),
),
here is the output:这是 output:
Material
is not necessary. Material
不是必需的。 If you want to adjust color transparency either use Colors.YOUR_COLOR.withOpacity(0.0.. to.. 1.0)
or Color.fromRGBO(RED, BLUE, GREEN, 0.0.. to.. 1.0)
如果要调整颜色透明度,请使用
Colors.YOUR_COLOR.withOpacity(0.0.. to.. 1.0)
或Color.fromRGBO(RED, BLUE, GREEN, 0.0.. to.. 1.0)
Examples:例子:
Colors.blue.withOpacity(0.3);
// OR
Color.fromRGBO(50, 45, 220, 0.3);
Edit编辑
You can simplify your layout like this.您可以像这样简化布局。
HomePage主页
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomContainer(
child: Column(
children: [
// other widgets and your containers here
],
),
),
);
}
}
Your CustomContainer Widget您的 CustomContainer 小部件
class CustomContainer extends StatelessWidget {
final Widget child;
CustomContainer({this.child});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomLeft,
colors: [
Color(0xFF1187be),
Color(0xff061465),
],
),
),
child: child,
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.