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),
),
),
),
)
Related
am trying to get this kind of half border with gradient color only top right and bottom left
Refer below snippet
Container(
height: 200,
width: 200,
// change padding value to modify width of border
padding: EdgeInsets.all(2),
// space between content and outer border
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.all(5),
// main content
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black45),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text("Content"),
),
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [Colors.blue, Colors.white, Colors.white, Colors.blue],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.1, 0.2, 0.8, 0.9],
),
),
)
I'm wondering if there is a simple way to give a circle avatar multiple border colors in Flutter.
Bonus if you could set the % you want each color to fill.
Here is an image of what I mean, but note it wasn't that easy to do in Figma, hence the blurring of the colors. Color blending actually would not be the preferred behavior.
This is what came to my mind. You can change the color list to match the Figma gradient.
Container(
height: 80,
width: 80,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [
Colors.green,
Colors.yellow,
Colors.red,
Colors.purple
]),
shape: BoxShape.circle),
child: Padding(
//this padding will be you border size
padding: const EdgeInsets.all(3.0),
child: Container(
decoration: const BoxDecoration(
color: Colors.white, shape: BoxShape.circle),
child: const CircleAvatar(
backgroundColor: Colors.white,
foregroundImage: NetworkImage("https://i.ibb.co/rkG8cCs/112921315-gettyimages-876284806.jpg"),
),
),
),
),
Here is your solution,
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Color(0XFF8134AF),
Color(0XFFDD2A7B),
Color(0XFFFEDA77),
Color(0XFFF58529),
],
),
shape: BoxShape.circle
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle
),
margin: EdgeInsets.all(2),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: CircleAvatar(
radius: 25,
backgroundColor: Colors.grey,
backgroundImage: NetworkImage(reels[i].image)
),
),
),
),
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.