File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-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
+ 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
+ }
You can’t perform that action at this time.
0 commit comments