I want to build a gradient shadow widget as shown below.
This gradient starts from black and end at white, how can I design this type of widget?
It can be done like this,
Container(
height:100,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.black, Colors.white],
begin: Alignment.topCenter,
end: Alignment.bottomCenter
)
),
),
The result is :
Are You looking for that result?
You can also try this:
Container(
height: 200,
width: 200,
decoration: BoxDecoration(
color: Colors.blue,
boxShadow: [
BoxShadow(
color: Colors.black,
offset: Offset(0, 10),
blurRadius: 10,
spreadRadius: 0.5,
),
],
),
)
Output
It mainly depends on your use case, for instance, if you want to show shadow you can directly use
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 100,
width: 100,
color: Colors.blue,
),
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black,
offset: Offset(0, 1),
blurRadius: 10,
spreadRadius: 0.5,
),
],
),
height: 10,
width: 100,
)
],
)
Output:
Related
how make gradient at flutter like this image?, i think this gradient make like 3D Effect
Try this:
Container(
width: 200,
height: 240,
child: Icon(Icons.android, size: 60, color: Colors.grey[100]),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(42)),
boxShadow: [
BoxShadow(
color: Colors.deepOrange[400],
offset: const Offset(0, 20),
blurRadius: 30,
spreadRadius: -5,
),
],
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomCenter,
colors: [
Colors.deepOrange[200],
Colors.deepOrange[300],
Colors.deepOrange[500],
Colors.deepOrange[500],
],
stops: const [
0.1,
0.3,
0.9,
1.0
])),
),
Result:
How to add elevation to a container with borderRadius
I have tried Material/elevation and ClipRRect.showBox but it doesn't look as good as regular elevation
You can use a Container with boxShadow and borderRadius like that for example:
Container(
width: 200,
height: 100,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
boxShadow: [
BoxShadow(
offset: Offset(0, 0),
blurRadius: 2,
spreadRadius: 2,
color: Colors.black26,
),
],
),
);
It will look something like that:
You can play with the shadows to achieve the elevation you want.
Add BoxShadow with grey shadow color, it will give an elevation effect.
Container(
height: 200, /// Change height and width as per your need.
width: 200,
child: Container(
color: Colors.red
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
Output:
How to add gradient color in the background of a card ? Should I reproduce this card with a container and a box decoration or is there another simple way ?
Try below code hope it help to you in below answer change Color your need.
Card(
child: Container(
height: 50,
width: 150,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.yellow,
Colors.orangeAccent,
Colors.yellow.shade300,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Container(), //declare your widget here
),
),
Your Card look like->
If you are gradient background to card or gradient border to card try below code
Container(
height: 50,
width: 150,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.yellow,
Colors.orangeAccent,
Colors.yellow.shade300,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child:Card(
color:Colors.white,
child: Container(), //declare your widget here
),
),
Your Screen like ->
I know it's a bit late, but you can try this to achieve a card gradient with border radius
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black38,
blurRadius: 3.0,
spreadRadius: 0.0,
offset: Offset(1.0, 1.0),
)
],
gradient: LinearGradient(
colors: [startColor, endColor],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 6),
TextWidget(
title,
typographyToken: TypographyToken.text14SemiBold,
color: Colors.white,
),
const SizedBox(height: 8),
TextWidget(
"$pendingCount Pending Request",
typographyToken: TypographyToken.text10,
color: Colors.white,
),
const SizedBox(height: 6),
],
),
),
);
Result :
result
This is a sample that I tried just now. Works fine for me.
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.black, Colors.white],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
)
Another way and probably the best in my opinion:
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerRight,
end: Alignment.center,
colors: [Colors.deepOrangeAccent, Colors.orange],
),
),
width: 300,
height: 300,
child: Card(
color: Colors.transparent,
),
),
Output:
Click here to view
Card(
shadowColor: tabColorAmber,
elevation: 10,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(colors: [
Colors.orangeAccent,
Colors.orangeAccent,
Colors.yellow.shade100,
])),
width: double.infinity,
height: 140,
),
),
Example
I want to make a container with gradient color and shadow. But shadow is always front from the gradient.
How can i fix this?
Container(
width: 184,
height: 127,
decoration: new BoxDecoration(
gradient: new LinearGradient(colors: [
Color(0xFFFFC1CD).withOpacity(0.6),
Color(0XFFA5E8FF).withOpacity(0.6),
], stops: [
0.0,
1.0
], begin: FractionalOffset.topCenter, end: FractionalOffset.bottomCenter, tileMode: TileMode.repeated),
boxShadow: [
BoxShadow(
color: Color(0xFF797D7F),
offset: Offset(0, 10),
blurRadius: 10,
spreadRadius: 0.5,
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {},
child: Center(
child: Text("Hi"),
)),
),
),
Make a container with box shadow and make the one with the gradient a child of it
Above is the expected output.
I need to implement this gradient in Flutter but it's not coming out as excepted.
Color: #6646E7
The color shift is very strict and not smooth as shown in the image.
Below is the container where I wanted to use the
Complete Code:
Stack(
alignment: Alignment.bottomRight,
children: [
Container(
margin: const EdgeInsets.only(left: 10, right: 10, top: 15),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
border: Border.all(color: Colors.white, width: 2),
// gradient: LinearGradient(
// begin: Alignment.topLeft,
// end: Alignment.bottomRight,
// stops: const [
// 0.01,
// 0.1,
// 0.9
// ],
// colors: [
// const Color(0xff6646E7).withOpacity(0.4),
// Colors.white,
// const Color(0xff6646E7).withOpacity(0.4),
// ]),
// boxShadow: [
// const BoxShadow(
// color: Color.fromRGBO(0, 0, 0, 0.25),
// blurRadius: 3,
// spreadRadius: 1,
// offset: Offset(0, 4))
// ]),
),
child: Column(
children: [
Row(
children: [
SvgPicture.asset('assets/profile/$icon.svg'),
const SizedBox(
width: 10,
),
Text(
title,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
fontFamily: GoogleFonts.poppins().fontFamily),
)
],
),
const SizedBox(
height: 20,
),
child
],
),
),
Positioned(
right: 10,
child: GestureDetector(
onTap: onEditPressed,
child: SvgPicture.asset('assets/profile/edit_pen.svg')),
)
],
);
Thanks for your help
Try this,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.black38,
Colors.black12,
Colors.black12,
Colors.black38,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
Change Colors.black38 & Colors.black12 with your desired colors.