Skip to content

Commit 1e560d6

Browse files
committed
NOMERGE inset_shadow [nfc]: Bring out a public helper, to use soon
1 parent 0c6e137 commit 1e560d6

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lib/widgets/inset_shadow.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ class InsetShadowBox extends StatelessWidget {
4848

4949
final Widget child;
5050

51-
BoxDecoration _shadowFrom(AlignmentGeometry begin) {
52-
return BoxDecoration(gradient: LinearGradient(
53-
begin: begin, end: -begin,
54-
colors: [color, color.withValues(alpha: 0)]));
55-
}
56-
5751
@override
5852
Widget build(BuildContext context) {
5953
return Stack(
@@ -63,13 +57,32 @@ class InsetShadowBox extends StatelessWidget {
6357
children: [
6458
child,
6559
if (top != 0) Positioned(top: 0, height: top, left: 0, right: 0,
66-
child: DecoratedBox(decoration: _shadowFrom(Alignment.topCenter))),
60+
child: DecoratedBox(
61+
decoration: fadeToTransparencyDecoration(FadeToTransparencyDirection.down, color))),
6762
if (bottom != 0) Positioned(bottom: 0, height: bottom, left: 0, right: 0,
68-
child: DecoratedBox(decoration: _shadowFrom(Alignment.bottomCenter))),
63+
child: DecoratedBox(
64+
decoration: fadeToTransparencyDecoration(FadeToTransparencyDirection.up, color))),
6965
if (start != 0) PositionedDirectional(start: 0, width: start, top: 0, bottom: 0,
70-
child: DecoratedBox(decoration: _shadowFrom(AlignmentDirectional.centerStart))),
66+
child: DecoratedBox(
67+
decoration: fadeToTransparencyDecoration(FadeToTransparencyDirection.end, color))),
7168
if (end != 0) PositionedDirectional(end: 0, width: end, top: 0, bottom: 0,
72-
child: DecoratedBox(decoration: _shadowFrom(AlignmentDirectional.centerEnd))),
69+
child: DecoratedBox(
70+
decoration: fadeToTransparencyDecoration(FadeToTransparencyDirection.start, color))),
7371
]);
7472
}
7573
}
74+
75+
enum FadeToTransparencyDirection { down, up, end, start }
76+
77+
BoxDecoration fadeToTransparencyDecoration(FadeToTransparencyDirection direction, Color color) {
78+
final begin = switch (direction) {
79+
FadeToTransparencyDirection.down => Alignment.topCenter,
80+
FadeToTransparencyDirection.up => Alignment.bottomCenter,
81+
FadeToTransparencyDirection.end => AlignmentDirectional.centerStart,
82+
FadeToTransparencyDirection.start => AlignmentDirectional.centerEnd,
83+
};
84+
85+
return BoxDecoration(gradient: LinearGradient(
86+
begin: begin, end: -begin,
87+
colors: [color, color.withValues(alpha: 0)]));
88+
}

0 commit comments

Comments
 (0)