How to add gradient color in card? - flutter

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

Related

How to make circle at background?

As show in the design I want to add this type circle for background but doesn't know how to do that? How can I achieve this circle background image:
This is how other content look on it
This is code snipt-
Container(
height: 200,
width: 200,
decoration:BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Color(0xffCB00FE),
Color(0xffFE0098),
Color(0xffFF8A00),
],
),
),
),
Try this:
#override
Widget build(BuildContext context) {
MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width;
return Scaffold(
appBar: AppBar(),
body: Stack(
children: [
Positioned(
top: 100,
right: 0,
child: Container(
height: 200,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100),
topLeft: Radius.circular(100),
),
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomRight,
colors: [
Colors.purple,
Colors.pink,
Colors.orange,
],
),
),
)),
Column(
children: [
Container(
height: 150,
margin: EdgeInsets.all(16),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(12),
),
),
SizedBox(
height: 16,
),
Container(
height: 150,
margin: EdgeInsets.all(16),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
),
],
),
],
),
);
}

How can i achieve this kind of border in Flutter

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],
),
),
)

How do you give a CircleAvatar multiple border colors in Flutter?

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)
),
),
),
),

Shadow blur efect in flutter

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,
],
),
),
),
),
],
)

Flutter - How to get linear gradient across all edges?

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,
],
)),
),
],
),