I am applying linear gradient on image, but the gradient transition is not smooth. please see the below image.
It has a line when gradient ends. how to have a smooth transition on gradient.
Container(
height: 350,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(25)),
boxShadow: const [BoxShadow(color: Color.fromRGBO(104, 104, 104, 0.2), offset: Offset(0, 1), spreadRadius: 5, blurRadius: 10)],
image: DecorationImage(
image: getImage(imageno: 123).image,
fit: BoxFit.cover,
),
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 225,
foregroundDecoration: const BoxDecoration(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(25.0), bottomRight: Radius.circular(25.0)),
gradient: LinearGradient(
colors: [
Color.fromRGBO(0, 0, 0, 0),
Color.fromRGBO(0, 0, 0, 0.65),
Color.fromRGBO(22, 22, 22, 0.81),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0, 0.3, 0.1],
),
),
),
),
)
It is because of your stops, it should be inline changes in your stops, your last stop is smaller that middle stop and that is the problem, change it to this:
stops: [0, 0.6, 1],
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:
LinearGradient(
//tileMode: TileMode.clamp,
colors: [
kRecordButtonColor.withOpacity(0.4),
kRecordButtonColor,
kRecordButtonColor,
kRecordButtonColor.withOpacity(0.4),
],
stops: const [
0,
0.2,
0.8,
1,
],
),
As you can see this code only helps me get gradients across 2 edges, I need it along all 4 edges.
Try this instead of your Container:
Stack(
alignment: Alignment.center,
children: [
Container(
margin: EdgeInsets.all(16.0),
width: 55,
height: 55,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Colors.red.withOpacity(0.5),
Colors.red,
Colors.red,
Colors.red.withOpacity(0.5),
],
stops: const [
0,
0.2,
0.8,
1,
],
)),
),
Container(
margin: EdgeInsets.all(16.0),
width: 55,
height: 55,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.white.withOpacity(0.5),
Colors.white.withOpacity(0.0),
Colors.white.withOpacity(0.0),
Colors.white.withOpacity(0.5),
],
stops: const [
0,
0.2,
0.8,
1,
],
)),
),
],
),
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
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:
I have this gradient on Android:
<gradient
android:angle="45.0"
android:centerColor="#ffeeeeee"
android:endColor="#ffbbbbbb"
android:startColor="#ffcccccc" />
I want it to replicate it on flutter but I'm unable to do so.
I have tried to use a LinearGradient but doesn't even come close to the one on Android.
I tried this:
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color(0xffeeeeee),
Color(0xffcccccc),
Color(0xffbbbbbb),
],
begin: Alignment(-1.0, -4.0),
end: Alignment(1.0, 4.0),
),
),
Thanks
You can do it like this
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.red, Colors.orange],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
child: Container(
)),
);
For color code, do like this
Color hexToColor(String code) {
return new Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000);
}
Try to add gradient as:
Container(height: 200,
width: 350,
decoration: BoxDecoration(
color: Colors.white,
gradient: LinearGradient(
begin: FractionalOffset.topCenter,
end: FractionalOffset.bottomCenter,
colors: [
Color.fromRGBO(0, 0, 0, 0.0),
Color.fromRGBO(0, 0, 0, 0.25),
Color.fromRGBO(0, 0, 0, 0.7),
],
stops: [0.5, 0.7, 0.9],
)),
),