IconButton with gradient overlay breaks when tapped - flutter

I have an IconButton with a gradient overlay, like this
Container(
foregroundDecoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.orange.shade100, Colors.orange.shade900],
begin: Alignment(0, 0),
end: Alignment(0, 1)
),
backgroundBlendMode: BlendMode.screen
),
child: IconButton(
icon: Icon(Icons.add_box),
iconSize: 36,
color: Colors.black,
onPressed: (){},
),
);
It looks great until I tap it, then suddenly the gradient covers the entire Container (and the IconButton) and stays there.
Is there a way to prevent it from breaking when tapping it?

It may be an option for you to wrap your Icon in the Container, instead of wrapping the whole IconButton.
IconButton(
icon: Container(
foregroundDecoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.orange.shade100, Colors.orange.shade900],
begin: Alignment(0, 0),
end: Alignment(0, 1),
),
backgroundBlendMode: BlendMode.screen),
child: Icon(Icons.add_box),
),
iconSize: 36,
color: Colors.black,
onPressed: () {},
),

Related

How to create a gradient button in flutter

I am trying to create a button similar to this one, I don't have exact colors so using yellow and black.
Want this
My Code Output
here is my code:
class CustomButton extends StatelessWidget {
final String? text;
double width;
final Function()? onPressed;
CustomButton({this.width = 0.8, this.text, this.onPressed});
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onPressed,
child: Container(
child: Center(
child: CustomTextWidget(
text: text!,
textColor: AppColors.BLACK_COLOR,
fontWeight: FontWeight.bold,
fontSize: 1.1,
)),
height: ScreenSize.heightSize * 0.08,
width: width.sw,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Colors.yellow, Colors.black],
begin: Alignment.topRight,
end: Alignment.topRight,
stops: [0.7, 0.8],
tileMode: TileMode.repeated,
),
borderRadius: BorderRadius.circular(4)),
),
);
}
}
Kindly help how to do this.
Try below code hope its help to you and used FractionalOffset
GestureDetector(
onTap: () {},
child: Container(
alignment: Alignment.center,
height: 44.0,
width: 100,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.yellow,
Colors.black,
],
begin: FractionalOffset.bottomCenter,
end: FractionalOffset.topCenter,
),
),
child: const Text('SIGN UP'),
),
),
Result->
You can modify your Linear Gradient like this:
LinearGradient(
colors: [
Color.fromARGB(100, 137, 90, 11),
Color.fromARGB(255, 252, 208, 72)
],
begin: Alignment.topCenter,
end: Alignment.center,
stops: [0.0, 0.3],
),
Output:
IMO, It looks better.
P.S. You can change colors & stops property as per your need.
Use this code for Gradient color in Elevated Button
Container(
height: 44.0,
decoration: BoxDecoration(gradient: LinearGradient(colors: [Colors.orange, Colors.green])),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(primary: Colors.transparent, shadowColor: Colors.transparent),
child: Text('Elevated Button'),
),
)

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

How to add gradient color in card?

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

How to make the Flutter app bar with gradient background

This question is being posted here as the related question here on stack overflow has only workarounds but no straight to the point approach.
this can be achieved with the fallowing code
AppBar(
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.cyan, Colors.yellow], stops: [0.5, 1.0],
),
),
),
),
See the Pen
bGVBVpz by yadunandan (#iamyadunandan)
on CodePen.
For a simple appbar with a gradient background and centered title,
AppBar(
automaticallyImplyLeading: false, // hides default back button
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.topRight,
colors: [
Color(0xffB1097C),
Color(0xff0947B1),
]),
)),
title: Text("WishList", style: TextStyle(fontSize: 20.0, color: Colors.white)),
centerTitle: true,
),
For a more complex appbar with a gradient background and action icons
AppBar(
automaticallyImplyLeading: false, // hides default back button
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.topRight,
colors: [
Color(0xffB1097C),
Color(0xff0947B1),
]),
)),
title: Text("Welcome guest", style: TextStyle(fontSize: 20.0, color: Colors.white)),
actions: [
IconButton(
icon: SvgPicture.asset("enter svg path",height: 20.0, width: 20.0),
onPressed: () {
print("Icon 1 pressed");
}),
IconButton(
icon: SvgPicture.asset("enter svg path", height: 20.0, width: 20.0),
onPressed: () {
print("Icon 2 pressed");
},
)
],
)

Create a groove button in flutter?

Is it posible to make a button like the image? It doesn't need to be circular just is there anyway to gice that groove effect to a raised button and text field areas in Flutter?
Also link of the image is "https://css-tricks.com/circular-3d-buttons/"
This is made by css, if there is any trick to do it with material design maybe css import for such a work?
You can get a pretty similar result by using a RawMaterialButton and a decorated Container.
Container(
padding: EdgeInsets.all(10),
decoration: new BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0.0 , 0.5, 1.0],
colors: [Colors.white, Colors.white, Colors.grey[200]]
)
),
child: RawMaterialButton(
onPressed: () {},
child: new Icon(
Icons.settings,
color: Colors.grey[600],
size: 28.0,
),
shape: new CircleBorder(),
elevation: 2.0,
fillColor: Colors.white,
padding: const EdgeInsets.all(18.0),
)
);
Try this
new RawMaterialButton(
onPressed: () {},
child: new Icon(
Icons.pause,
color: Colors.blue,
size: 35.0,
),
shape: new CircleBorder(),
elevation: 2.0,
fillColor: Colors.white,
padding: const EdgeInsets.all(15.0),
),