bubble_widget.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. import 'bubble_border_arrow_properties.dart';
  3. /// 气泡组件
  4. class BubbleWidget extends StatelessWidget {
  5. final BorderSide border;
  6. final AxisDirection arrowDirection;
  7. final BorderRadius? borderRadius;
  8. final double arrowLength;
  9. final double arrowWidth;
  10. final double? arrowOffset;
  11. final double arrowRadius;
  12. final Color? backgroundColor;
  13. final EdgeInsets? padding;
  14. final WidgetBuilder contentBuilder;
  15. final List<BoxShadow>? shadows;
  16. final EdgeInsetsGeometry? margin;
  17. const BubbleWidget({
  18. super.key,
  19. required this.arrowDirection,
  20. this.arrowOffset,
  21. required this.contentBuilder,
  22. this.border = BorderSide.none,
  23. this.borderRadius,
  24. this.arrowLength = 10,
  25. this.arrowWidth = 17,
  26. this.arrowRadius = 3,
  27. this.backgroundColor,
  28. this.shadows,
  29. this.padding,
  30. this.margin,
  31. });
  32. @override
  33. Widget build(BuildContext context) {
  34. EdgeInsets bubblePadding = EdgeInsets.zero;
  35. if (arrowDirection == AxisDirection.up) {
  36. bubblePadding = EdgeInsets.only(top: arrowLength);
  37. } else if (arrowDirection == AxisDirection.down) {
  38. bubblePadding = EdgeInsets.only(bottom: arrowLength);
  39. } else if (arrowDirection == AxisDirection.left) {
  40. bubblePadding = EdgeInsets.only(left: arrowLength);
  41. } else if (arrowDirection == AxisDirection.right) {
  42. bubblePadding = EdgeInsets.only(right: arrowLength);
  43. }
  44. return Container(
  45. margin: margin,
  46. decoration: ShapeDecoration(
  47. shape: BubbleShapeBorder(
  48. side: border,
  49. arrowDirection: arrowDirection,
  50. borderRadius: borderRadius ?? BorderRadius.circular(4),
  51. arrowLength: arrowLength,
  52. arrowWidth: arrowWidth,
  53. arrowRadius: arrowRadius,
  54. arrowOffset: arrowOffset,
  55. fillColor: backgroundColor ?? const Color.fromARGB(255, 65, 65, 65),
  56. ),
  57. shadows: shadows,
  58. ),
  59. child: Padding(
  60. padding: bubblePadding.add(padding ?? EdgeInsets.zero),
  61. child: contentBuilder(context),
  62. ),
  63. );
  64. }
  65. }