Skip to content

Commit 490c274

Browse files
committed
compose_box [nfc]: Add InsetShadowBox
This casts a static shadow on top of a child widget from its top edge and bottom edge. Signed-off-by: Zixuan James Li <[email protected]>
1 parent a435083 commit 490c274

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib/widgets/inset_shadow_box.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// A widget that overlays inset shadows on a child.
4+
class InsetShadowBox extends StatelessWidget {
5+
const InsetShadowBox({
6+
this.top = 0,
7+
this.bottom = 0,
8+
required this.color,
9+
required this.child,
10+
});
11+
12+
/// The distance that the shadows from the child's top edge grows downwards.
13+
///
14+
/// This does not pad the child widget.
15+
final double top;
16+
17+
/// The distance that the shadows from the child's bottom edge grows upwards.
18+
///
19+
/// This does not pad the child widget.
20+
final double bottom;
21+
22+
/// The shadow color to fade into transparency from the top and bottom borders.
23+
final Color color;
24+
25+
final Widget child;
26+
27+
BoxDecoration _shadowFrom(AlignmentGeometry begin) {
28+
return BoxDecoration(gradient: LinearGradient(
29+
begin: begin, end: -begin,
30+
colors: [color, color.withValues(alpha: 0)]));
31+
}
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return Stack(
36+
children: [
37+
child,
38+
Positioned(top: 0, left: 0, right: 0,
39+
child: Container(height: top, decoration: _shadowFrom(Alignment.topCenter))),
40+
Positioned(bottom: 0, left: 0, right: 0,
41+
child: Container(height: bottom, decoration: _shadowFrom(Alignment.bottomCenter))),
42+
]);
43+
}
44+
}

0 commit comments

Comments
 (0)