popmenu_bg.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/painting.dart';
  4. class PopmenuShape extends ShapeBorder {
  5. final double borderWidth;
  6. final BorderRadius borderRadius;
  7. final Color backgroundColor;
  8. const PopmenuShape({
  9. this.borderWidth: 1.0,
  10. this.borderRadius: BorderRadius.zero,
  11. this.backgroundColor: Colors.white,
  12. }) : assert(borderRadius != null);
  13. @override
  14. EdgeInsetsGeometry get dimensions {
  15. return new EdgeInsets.all(borderWidth);
  16. }
  17. @override
  18. ShapeBorder scale(double t) {
  19. return PopmenuShape(
  20. borderWidth: borderWidth * (t),
  21. borderRadius: borderRadius * (t),
  22. );
  23. }
  24. @override
  25. Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
  26. return new Path()
  27. ..addRRect(borderRadius
  28. .resolve(textDirection)
  29. .toRRect(rect)
  30. .deflate(borderWidth));
  31. }
  32. @override
  33. Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
  34. return new Path()
  35. ..addRRect(borderRadius.resolve(textDirection).toRRect(rect));
  36. }
  37. @override
  38. void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
  39. rect = rect.deflate(borderWidth / 2.0);
  40. final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect);
  41. Paint paint = new Paint()
  42. ..color = backgroundColor
  43. ..style = PaintingStyle.fill
  44. ..strokeWidth = borderWidth;
  45. // canvas.drawRRect(borderRect,paint);
  46. Path path = Path()
  47. ..moveTo(borderRect.width - 10, borderRect.top)
  48. ..lineTo(borderRect.width - 20, borderRect.top - 10)
  49. ..lineTo(borderRect.width - 30, borderRect.top);
  50. // path.addRRect(borderRect);
  51. // canvas.drawShadow(
  52. // path,
  53. // Color(0xffdcdcdc),
  54. // 1,
  55. // false);
  56. canvas.drawPath(path, paint);
  57. }
  58. }