Skip to content

Instantly share code, notes, and snippets.

@Abdurrahman98XX
Created May 23, 2023 09:47
Show Gist options
  • Select an option

  • Save Abdurrahman98XX/a3d9df1f1e248f46efc9f091ce9f7c19 to your computer and use it in GitHub Desktop.

Select an option

Save Abdurrahman98XX/a3d9df1f1e248f46efc9f091ce9f7c19 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class HarryPoter extends StatefulWidget {
const HarryPoter({
super.key,
required this.child,
});
final Widget child;
@override
State<HarryPoter> createState() => _HarryPoterState();
}
class _HarryPoterState extends State<HarryPoter> {
Offset offset = Offset.zero;
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(color: Colors.green),
MouseRegion(
onHover: (event) => setState(() => offset = event.localPosition),
child: ClipPath(
clipper: CircleClipper(
center: offset,
radius: 200,
),
child: widget.child,
),
),
],
);
}
}
class CircleClipper extends CustomClipper<Path> {
final Offset center;
final double radius;
const CircleClipper({
required this.center,
required this.radius,
super.reclip,
});
@override
Path getClip(Size size) {
return Path()..addOval(Rect.fromCircle(center: center, radius: radius));
}
@override
bool shouldReclip(covariant CircleClipper oldClipper) {
return oldClipper.center != center || oldClipper.radius != radius;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment