Skip to content

Instantly share code, notes, and snippets.

@happyharis
Forked from coman3/ClipShadowPath.dart
Last active April 11, 2023 04:01
Show Gist options
  • Save happyharis/f03e713d8de35aef00c98078ffbed65a to your computer and use it in GitHub Desktop.
Save happyharis/f03e713d8de35aef00c98078ffbed65a to your computer and use it in GitHub Desktop.
ClipShadowPath with BoxShadow params
import 'package:flutter/material.dart';
@immutable
class ClipShadowPath extends StatelessWidget {
final BoxShadow shadow;
final CustomClipper<Path> clipper;
final Widget child;
ClipShadowPath({
@required this.shadow,
@required this.clipper,
@required this.child,
});
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: _ClipShadowShadowPainter(
clipper: this.clipper,
shadow: this.shadow,
),
child: ClipPath(child: child, clipper: this.clipper),
);
}
}
class _ClipShadowShadowPainter extends CustomPainter {
final BoxShadow shadow;
final CustomClipper<Path> clipper;
_ClipShadowShadowPainter({@required this.shadow, @required this.clipper});
@override
void paint(Canvas canvas, Size size) {
var paint = shadow.toPaint()
..maskFilter = MaskFilter.blur(
BlurStyle.normal,
shadow.spreadRadius,
);
var clipPath = clipper.getClip(size).shift(shadow.offset);
canvas.drawPath(clipPath, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment