Skip to content

Instantly share code, notes, and snippets.

@multiarts
Forked from coman3/ClipShadowPath.dart
Last active May 11, 2024 23:44
Show Gist options
  • Save multiarts/6d732a5a99278ce359bbf16c005f7c85 to your computer and use it in GitHub Desktop.
Save multiarts/6d732a5a99278ce359bbf16c005f7c85 to your computer and use it in GitHub Desktop.
Updated to null safety
import 'package:flutter/material.dart';
class ClipShadowPath extends StatelessWidget {
final Shadow shadow;
final CustomClipper<Path> clipper;
final Widget child;
const ClipShadowPath({
Key? key,
required this.shadow,
required this.clipper,
required this.child,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: _ClipShadowShadowPainter(
clipper: clipper,
shadow: shadow,
),
child: ClipPath(child: child, clipper: clipper),
);
}
}
class _ClipShadowShadowPainter extends CustomPainter {
final Shadow shadow;
final CustomClipper<Path> clipper;
_ClipShadowShadowPainter({required this.shadow, required this.clipper});
@override
void paint(Canvas canvas, Size size) {
var paint = shadow.toPaint();
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