Created
May 23, 2023 09:47
-
-
Save Abdurrahman98XX/a3d9df1f1e248f46efc9f091ce9f7c19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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