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
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 can I create this shadow blur in the top and bottom of the Widget that appears to be on top of the list?
try to wrap your child with Stack and a mask:
Stack(
children: [
//_yourWidget(),
Opacity(
opacity: 0.5,
child: Container(
width: 50.0,
height: 50.0,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[
Colors.black,
Colors.transparent,
Colors.transparent,
Colors.black,
],
stops: [
0,
0.2,
0.8,
1,
],
),
),
),
),
],
)
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 have colored Containers with a linearGradient on them.
Container(
padding: EdgeInsets.only(left: 7.0),
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Colors.black12,
),
borderRadius: BorderRadius.all(
Radius.circular(7.0)
),
boxShadow: [
BoxShadow(
offset: Offset(1, 3),
blurRadius: 5.0,
color: Colors.grey,
)
],
gradient: LinearGradient(
colors: [
_changeColorBrightness(widget.item.color, 0.1),
_changeColorBrightness(widget.item.color, -0.1),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
),
To get the colors for the gradient I brighten/darken the color on the sides:
Color _changeColorBrightness(Color color, double deltaValue) {
HSVColor hsvColor = HSVColor.fromColor(color);
double newValue = hsvColor.value + deltaValue;
if (newValue < 0.0) {
newValue = 0.0;
} else if (newValue > 1.0) {
newValue = 1.0;
}
return hsvColor.withValue(newValue).toColor();
}
Every color gradient looks as intended except for black:
My first thought was that it has to to with the fact that the color gradient isn't as big for black as it is for the other colors (I can't darken black on the right side).
But when I looked at the colors for the black gradient, they are 0xff1a1a1a and 0xff000000. And if I make the gradient bigger, the stripes remain in the black items, even if there are more stripes then.
Why is that and how can I avoid it?
Try this if its fine for your design,
Padding(
padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 0.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
padding: new EdgeInsets.only(top: 0.0),
child: new Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
child: ListTile(
subtitle: Text("This is Dummy Data",style: TextStyle(
color: Colors.white
),),
title: Text("Hello World",style: TextStyle(
color: Colors.white
),),
)),
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [
Colors.black,
Colors.black54,
/*AppColours.appgradientfirstColour,
AppColours.appgradientsecondColour*/
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(0.5, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
borderRadius: BorderRadius.circular(12.0),
),
),
),
)
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: