ticket_widget.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // ignore_for_file: library_private_types_in_public_api
  2. library ticket_widget;
  3. import 'package:flutter/material.dart';
  4. import 'package:general_package/clip_shadow/clip_shadow.dart';
  5. class TicketWidget extends StatefulWidget {
  6. const TicketWidget({
  7. Key? key,
  8. required this.width,
  9. required this.height,
  10. required this.child,
  11. this.padding,
  12. this.margin,
  13. this.color = Colors.white,
  14. this.isCornerRounded = false,
  15. required this.shadow,
  16. }) : super(key: key);
  17. final double width;
  18. final double height;
  19. final Widget child;
  20. final Color color;
  21. final bool isCornerRounded;
  22. final EdgeInsetsGeometry? padding;
  23. final EdgeInsetsGeometry? margin;
  24. final List<BoxShadow> shadow;
  25. @override
  26. _TicketWidgetState createState() => _TicketWidgetState();
  27. }
  28. class _TicketWidgetState extends State<TicketWidget> {
  29. @override
  30. Widget build(BuildContext context) {
  31. return Container(
  32. margin: widget.margin,
  33. child: ClipShadow(
  34. boxShadow: widget.shadow,
  35. clipper: TicketClipper(),
  36. child: AnimatedContainer(
  37. duration: const Duration(seconds: 1),
  38. width: widget.width,
  39. height: widget.height,
  40. padding: widget.padding,
  41. decoration: BoxDecoration(
  42. color: widget.color,
  43. borderRadius: widget.isCornerRounded
  44. ? BorderRadius.circular(20.0)
  45. : BorderRadius.circular(0.0),
  46. ),
  47. child: widget.child,
  48. ),
  49. ),
  50. );
  51. }
  52. }
  53. class TicketClipper extends CustomClipper<Path> {
  54. @override
  55. Path getClip(Size size) {
  56. Path path = Path();
  57. path.lineTo(0.0, size.height);
  58. path.lineTo(size.width, size.height);
  59. path.lineTo(size.width, 0.0);
  60. path.addOval(
  61. Rect.fromCircle(center: Offset(0.0, size.height / 2), radius: 20.0));
  62. path.addOval(Rect.fromCircle(
  63. center: Offset(size.width, size.height / 2), radius: 20.0));
  64. return path;
  65. }
  66. @override
  67. bool shouldReclip(CustomClipper<Path> oldClipper) => false;
  68. }