Created with <3 with dartpad.dev.
Created
December 7, 2022 15:20
-
-
Save knaeckeKami/eaaf84b0c135d6330cd01304be879b44 to your computer and use it in GitHub Desktop.
astonishing-spray-1411
This file contains 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'; | |
import 'dart:math'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MaterialApp(home: Scaffold(body :CircleClipperSlider(child: Container( | |
height: 200, | |
width: 200, | |
color: Colors.orange))))); | |
} | |
class CircleClipper extends StatelessWidget { | |
final double angle; | |
final Widget child; | |
CircleClipper({required this.angle, required this.child}); | |
@override | |
Widget build(BuildContext context) { | |
return ClipPath( | |
clipper: CircleClipperPath(angle: angle), | |
child: child, | |
); | |
} | |
} | |
class CircleClipperPath extends CustomClipper<Path> { | |
final double angle; | |
CircleClipperPath({required this.angle}); | |
@override | |
Path getClip(Size size) { | |
final Path path = Path(); | |
path.moveTo(size.width / 2, size.height / 2); | |
path.arcTo( | |
Rect.fromLTWH(0, 0, size.width, size.height), | |
-pi / 2, | |
angle, | |
false, | |
); | |
path.close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(CircleClipperPath oldClipper) => | |
oldClipper.angle != angle; | |
} | |
class CircleClipperSlider extends StatefulWidget { | |
final Widget child; | |
CircleClipperSlider({required this.child}); | |
@override | |
_CircleClipperState createState() => _CircleClipperState(); | |
} | |
class _CircleClipperState extends State<CircleClipperSlider> { | |
double _angle = pi/8; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
CircleClipper( | |
angle: _angle, | |
child: widget.child, | |
), | |
Slider( | |
value: _angle, | |
min: 0, | |
max: 2.0 * pi, | |
onChanged: (value) { | |
setState(() { | |
_angle = value; | |
}); | |
}, | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment