-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShadowBox inset attribute? Inner shadow #18636
Comments
cc @HansMuller |
The Material widget has an elevation (and a shape!). It's rendered with a shadow that's based on the elevation. |
@HansMuller I think he is looking for an inside shadow like https://css-tricks.com/snippets/css/css-box-shadow/#article-header-id-2 |
@zoechi provided example what I want achieve |
@zoechi I see. We don't have explicit support for "inward" shadows however that seems like a reasonable thing to add. |
You can add paralax to an image, lets say a header image for a listing, but then also adding an inner shadow so it looks set back would give a great 3d effect people would want to be able to do. |
I'm looking for this feature in order to add inner shadow to the background widget of dismissible widgets. That way it would appear as though my list tiles are elevated above it. |
Its important to add that this should be transparent, or support transparency. The same effect can be created with no transparency by stacking boxShadow's but you are left with the top boxShadow's color. What would be nice is to be able to put this "over" another item, in a stack and this shadow effect shows through to the stack below. |
I wanted to use this feature to add an inset shadow on my map widget, so that it could look embedded in the page. Unfortunately I can't find a workaround for this. |
Any further work on this? |
Do we have an update on this feature? |
Also looking for this feature |
To add on to this, a lot of people are looking for this to work on "neumorphism UI" elements to their applications |
I'd also love to see inset shadows for text. |
Any news about this? |
I am actually surprised. Seeing as animation and 'Beautiful UI' is one of the main selling points for flutter, I would have imagined this feature would be taken more seriously. Instead it is on the back burner "Stretch goals". I would offer to help with it, but sadly I am far from experienced with the inner workings Flutter. |
Hey guys how is your day? |
May be this can help >> https://www.youtube.com/watch?v=oTYDD3nZ-ZA |
I found this approach. and it is what I am using. |
If you are here because you wish to make a neumorphic button, you really don't need a inner shadow, try the following code for a circular container over a boxShadow: _selected
? [
BoxShadow(
color: Colors.black26,
blurRadius: 20,
spreadRadius: 2,
offset: Offset(12, 12),
),
BoxShadow(
color: Colors.white70,
blurRadius: 20,
spreadRadius: 2,
offset: Offset(-12, -12),
),
]
: [
BoxShadow(
color: Colors.black26,
blurRadius: 30,
spreadRadius: 2,
offset: Offset(-12, -12),
),
BoxShadow(
color: Colors.white60,
blurRadius: 20,
spreadRadius: 2,
offset: Offset(12, 12),
),
] Play with this and you have the desired effect.. P.S. Lighter color has to be after the darker one when defining boxShadows. The full code for the same is here- https://gist.github.com/bhaskar-nair2/88bdb05f3d776b6a94c430fbd048e67f |
And (as far as I've seen) there seems to be no good hacked together solution for text anyways |
Where is this? I can't believe a modern framework doesn't have such a basic UI element. |
I think what most of us are looking for is an Inner Box Bevel with similar parameters as Photoshop Blending Options, but the way to hack that in CSS is using an inset shadow. It would be nice if BoxShadow has an option to make inset: true, or to allow blurRadius & spreadRadius be a negative value. It would also be amazing to have a boxDecoration component like boxBevel: BoxBevel(depth: 22, size: 7, soften: 2, angle: -39, altitude: 26, highlightColor: Colors.white54, shadowColor: Colors.black54, highlightBlendMode: BlendMode.screen, shadowBlendMode: BlendMode.multiply, style: BoxBevelStyle.smooth), and to do the same for TextBevel.. |
I vote for this too, been hacking at this for days now. |
Inner Shadow property would be very useful for (rounded) TextFields. Maybe the trend is already outdated when this is introduced ;) |
This source was useful for me. Base on this source I built a circle with transparent background and the same time the circle has an inner shadows. In short, need to use RadialGradient in an Container's BoxDecoration.
|
@MaximRyabovol thank you so much for your comment, that is EXACTLY what I needed! |
any hope this will ever be added? now that web is officially supported I would expect that such a basic task would be easy to achieve, specially if flutter wants to conquer developers that are already used to how easy things like this are in CSS |
I vote for this implementation. |
I had an idea about inner shadow implementation and creating neumorphism effect in Flutter. How about creating the parent container (with Have a look at code here :) I hope i have helped at least someone 😄 |
Please refer to #88697 |
@deepak-penaganti @Piinks @dnfield I'm providing an example with CSS and Flutter below to make this clear. You can even try this on Figma. Inner Shadow Specification
CSS ExampleCSS Sample Code<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
padding: 10px;
box-shadow: inset 0px 2px 10px rgba(0, 0, 0, 1);
}
</style>
</head>
<body>
<h2>box-shadow</h2>
<div id="example1">
<p>A div element with a shadow. The first value is the horizontal offset and the second value is the vertical offset. The shadow color will be inherited from the text color.</p>
</div>
</body>
</html> Flutter ExampleFlutter Sample Codeclass Demo extends StatelessWidget {
const Demo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: SizedBox(
width: 200,
height: 200,
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurStyle: BlurStyle.inner,
color: Color(0xFF000000),
offset: Offset(0, 2),
blurRadius: 4,
),
],
),
),
),
),
);
}
}
IssueOn Flutter the color is getting applied to the entire container. While what was expected was a inner shadow with a blur of 10 & offest of (0, 2) as seen in the CSS sample. Hence, what happens with |
any update on this? |
It's been 4 years, and it's still open. Is there any easy way to achieve the same behavior CSS has? |
found a simple solution for now! you can use Stack and LinearGradient together so you can mimic the inset shadow similar to CSS... example :
try playing with the colors in LinearGradient to get the result you want |
@flar - this request has been simmering for a long (long) time. Do you think it would be possible to add support for inner shadows like this example #18636 (comment) ? |
Hi, I found a workaround solution in https://github.com/happyharis/neumorphic Container(
decoration: BoxDecoration(
boxShadow: [
//CSS: inset 0px 4px 6px rgba(8, 56, 73, 0.5)
BoxShadow(
color: const Color.fromRGBO(8, 56, 73, 0.5), // shadow color
),
const BoxShadow(
offset: Offset(0, 4),
blurRadius: 6,
color: Color(0xFFF9F8F9), // background color
),
],
borderRadius: BorderRadius.circular(25),
),
child: TextField(...),
), I hope this helps someone. |
React Native developer here 🙋🏼♂️ We implemented inner shadows using the following combination of Skia image filters: const f1 = ImageFilter.MakeColorFilter(
ColorFilter.MakeBlend(cl, BlendMode.SrcOut),
null
);
const f2 = ImageFilter.MakeOffset(dx, dy, f1);
const f3 = ImageFilter.MakeBlur(blur, blur, TileMode.Decal, f2);
const f4 = ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);
if (shadowOnly) {
return f4;
}
return ImageFilter.MakeCompose(
input,
ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)
); Does the recipe look correct? As far as we tested it, it seems to work nicely. I'm curious why this is not an available part of Skia (drop shadow is) and why this is not part of Flutter either. Are there some challenges with this implementation that we may be overlooking? |
Hello everyone! 😄 We have just published this package: https://pub.dev/packages/flutter_inset_box_shadow. It adds an The algorithm used is the same as the one used by Blink, the Chromium renderer: we draw a rectangle hollowed by another rounded rectangle, then we blur this hollowed rectangle. It is possible that there are still bugs in some cases, do not hesitate to inform us by creating an issue. I hope it will be useful to some! |
@johynpapin congrats! I wanted to check blink's source code for this but struggled to find the relevant file, you could point it to me? |
Thank you! 🙏 Here is the link to the main function that handles this: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/paint/box_painter_base.cc;l=254;drc=98cdb728ae59ac1151f4406d426233f86498eedd;bpv=1;bpt=1 EDIT: I can create a pull request to Flutter if the method is good. |
This is the most efficient implementation I've seen so far. I tried a few cases with Figma and it looks the same to naked eye. I had resorted to a work around which was also based on a similar approach but we had to use TIL Thanks for sharing, looking forward for this to be implemented along with BoxDecoration. |
@johynpapin Thank you for sharing your implementation 🙌🏼 We will use it for boxes as well since it is much faster. For anything else like path or text inner shadows, the implementation in my last comment is the way to go. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Maybe we could apply some shaders to reach the desired effects without performance drop (in https://pub.dev/packages/flutter_inset_box_shadow package)? |
This comment was marked as duplicate.
This comment was marked as duplicate.
Any update on this 6 year old feature request? I came here, because I want to have top and bottom inner shadow for a SingleChildScrollView, but the solution given in #24567 does not work at all. It is hard to believe that flutter does not support such a common feature. |
I didn't find any trace of inner shadow for box.
Like in CSS using box-shadow: inset there is a option to achieve the same effect?
The text was updated successfully, but these errors were encountered: