File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
+ super .key,
7
+ this .top = 0 ,
8
+ this .bottom = 0 ,
9
+ required this .color,
10
+ required this .child,
11
+ });
12
+
13
+ /// The distance that the shadows from the child's top edge grows downwards.
14
+ ///
15
+ /// This does not pad the child widget.
16
+ final double top;
17
+
18
+ /// The distance that the shadows from the child's bottom edge grows upwards.
19
+ ///
20
+ /// This does not pad the child widget.
21
+ final double bottom;
22
+
23
+ /// The shadow color to fade into transparency from the top and bottom borders.
24
+ final Color color;
25
+
26
+ final Widget child;
27
+
28
+ BoxDecoration _shadowFrom (AlignmentGeometry begin) {
29
+ return BoxDecoration (gradient: LinearGradient (
30
+ begin: begin, end: - begin,
31
+ colors: [color, color.withValues (alpha: 0 )]));
32
+ }
33
+
34
+ @override
35
+ Widget build (BuildContext context) {
36
+ return Stack (
37
+ children: [
38
+ child,
39
+ Positioned (top: 0 , left: 0 , right: 0 ,
40
+ child: Container (height: top, decoration: _shadowFrom (Alignment .topCenter))),
41
+ Positioned (bottom: 0 , left: 0 , right: 0 ,
42
+ child: Container (height: bottom, decoration: _shadowFrom (Alignment .bottomCenter))),
43
+ ]);
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments