Flutter box shadow - flutter

I am trying to develop shadow property for an inkwell with child of svg image.
This is what I trying to get done:,
And, this is what I am getting:
Can I get help with this? Here is my code:
new InkWell(
onTap: _googleSignIn,
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
color: Hexcolor('#e9f1fe'),
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Hexcolor('#C5D6F2'),
offset: Offset(6.0, 6.0),
blurRadius: 8.0,
spreadRadius: 1.0),
BoxShadow(
color: Colors.white,
offset: Offset(-4.0, -4.0),
blurRadius: 15.0,
spreadRadius: 1.0),
]),
child: SvgPicture.asset('assets/icon/google.svg',fit: BoxFit.fill,),
)),

Try change offset
offset: Offset(0.0, 0.0),

Related

How to add elevation to a container with borderRadius

How to add elevation to a container with borderRadius
I have tried Material/elevation and ClipRRect.showBox but it doesn't look as good as regular elevation
You can use a Container with boxShadow and borderRadius like that for example:
Container(
width: 200,
height: 100,
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(15.0),
),
boxShadow: [
BoxShadow(
offset: Offset(0, 0),
blurRadius: 2,
spreadRadius: 2,
color: Colors.black26,
),
],
),
);
It will look something like that:
You can play with the shadows to achieve the elevation you want.
Add BoxShadow with grey shadow color, it will give an elevation effect.
Container(
height: 200, /// Change height and width as per your need.
width: 200,
child: Container(
color: Colors.red
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
Output:

Flutter BoxShadow overlapping siblings

I'm trying to create a Row of containers that all have a BoxShadow. The shadows are quite large and therefore span into space that's outside of the parent, so I'm using clipBehavior: Clip.none on the parent.
The problem with this is that for each Container within the row it's shadow overlaps into the previous container. I've set some bold colors below to emphasize the issue. As you can see the right-hand side of the previous Container gets the shadow from the next.
Here's my code
return SingleChildScrollView(
clipBehavior: Clip.none,
scrollDirection: Axis.horizontal,
child: Row(
children: [
_ShadowedBox(),
_ShadowedBox(),
_ShadowedBox(),
],
),
);
class _ShadowedBox extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: 144,
child: Column(
children: [
SizedBox(
width: 144,
height: 144,
child: Container(
decoration: BoxDecoration(
color: Colors.grey,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(cardRadius),
boxShadow: [
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 38.0,
spreadRadius: 0.0,
color: Colors.red,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 46.0,
spreadRadius: 0.0,
color: Colors.green,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 10.0,
spreadRadius: 0.0,
color: Colors.blue,
),
]
),
child: ClipRRect(
borderRadius: BorderRadius.circular(cardRadius),
child: Image.network("https://via.placeholder.com/400x400.png?text=Coming%20soon", fit: BoxFit.contain)
),
),
],
),
);
}
}
Can anyone suggest how to stop the shadow bleeding into the other containers while still being able to show the shadows not being clipped by the parent?
Okay I've tested 2 approaches to fix your issue. As Wapazz said, each of your Container is drawn separately with its own shadow so they will overlap.
Solution #1
A solution could be to apply the shadow effect to your Row widget instead of the _ShadowedBox but the shadow effect wouldn't be as precise:
Code
SingleChildScrollView(
clipBehavior: Clip.none,
scrollDirection: Axis.horizontal,
child: UnconstrainedBox(
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 38.0,
spreadRadius: 0.0,
color: Colors.red,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 46.0,
spreadRadius: 0.0,
color: Colors.green,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 10.0,
spreadRadius: 0.0,
color: Colors.blue,
),
],
),
child: Row(
children: List<Widget>.generate(10, (_) => _ShadowedBox()),
),
),
),
),
Result
Solution #2
The other solution I've found would be to use a Stack widget with all the shadows rendered in a separate Row, so the resulting shadows have the correct shape. The issue with this method being that you need a fixed width and height for your widget:
Code
SingleChildScrollView(
clipBehavior: Clip.none,
scrollDirection: Axis.horizontal,
child: Stack(
children: [
Row(
children: List<Widget>.generate(
10,
(_) => Container(
margin: const EdgeInsets.symmetric(horizontal: 4),
width: 144,
height: 144,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(cardRadius),
boxShadow: [
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 38.0,
spreadRadius: 0.0,
color: Colors.red,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 46.0,
spreadRadius: 0.0,
color: Colors.green,
),
BoxShadow(
offset: const Offset(0.0, 6.0),
blurRadius: 10.0,
spreadRadius: 0.0,
color: Colors.blue,
),
],
),
),
),
),
Row(
children: List<Widget>.generate(10, (_) => _ShadowedBox()),
),
],
),
)
Result
You can try my full test code on DartPad

Flutter gradient rainbow outline and blur

I'm revisiting the flutter and want to build my small test application.
I'm opting for dark mode with nice gradient contrasts.
Would like to ask how I could achieve the rainbow outline with outside blur effect in Flutter.
Apple M1 logo has a great example of what I look for. Anyone could suggest how this can be done ??
It can be done by BoxShadow inside BoxDecoration if you position the shadow well because you can put as many shadows as you can.
I just give a simple example how to do with it with 4 colors:
#override
Widget build(BuildContext context) {
return Center(
child: Container(
decoration: BoxDecoration(boxShadow: [
BoxShadow(
offset: Offset(-20, 20),
color: Colors.red,
blurRadius: 15,
spreadRadius: -10,
),
BoxShadow(
offset: Offset(-20, -20),
color: Colors.orange,
blurRadius: 15,
spreadRadius: -10,
),
BoxShadow(
offset: Offset(20, -20),
color: Colors.blue,
blurRadius: 15,
spreadRadius: -10,
),
BoxShadow(
offset: Offset(20, 20),
color: Colors.deepPurple,
blurRadius: 15,
spreadRadius: -10,
)
]),
child: Container(
width: 200,
height: 200,
color: Colors.black,
child: Center(
child: Text(
'Text',
style: TextStyle(color: Colors.white, fontSize: 40),
)),
),
),
);
}
The output should look like this:

How to add outer glow (box shadow?) properly on button

How can I add this outer glow shadow to this button on Flutter?
On Figma:
It's done by either
filter: drop-shadow(0px 0px 20px rgba(255, 85, 85, 0.7));
or
Effect: Drop Shadow
Radius: 20px
Offset: 0px, 0px
rgba(255, 85, 85, 0.7)
Applying a BoxShadow to the container which contains the button does not work:
BoxShadow(
color: Color.fromRGBO(0, 0, 0, _opacity),
offset: Offset(_xOffset, _yOffset),
blurRadius: _blurRadius,
spreadRadius: _spreadRadius,
Because it's constrained by the container size.
With blurRadius and if you want to make color more visible add spreadRadius value.
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Colors.black, width: 2),
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius: 30,
),
],
),
Wrap button with the container and give it box-shadow property.
it works...
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18.0),
),
color: Colors.red,
boxShadow: [
BoxShadow(
color: Colors.pink,
spreadRadius: 4,
blurRadius: 10,
offset: Offset(0, 0),
)
]),
child: FlatButton(
onPressed:(){},
child: Text("submit"),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
),
),

Flutter make simple gradient shadow

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: