1+ import 'dart:math' ;
2+
13import 'package:flutter/material.dart' ;
24import 'package:flutter_text_decorator/src/modules/box/decorations/bubble_box_tip.dart' ;
35
@@ -22,14 +24,14 @@ import 'package:flutter_text_decorator/src/modules/box/decorations/bubble_box_ti
2224class BubbleBoxPainter extends CustomPainter {
2325 BubbleBoxPainter ({
2426 required this .text,
25- required this .padding,
2627 required this .bubbleColor,
28+ this .padding = const EdgeInsets .all (8 ),
2729 super .repaint,
2830 this .borderRadius = 8 ,
2931 this .tip = const BubbleBoxTip (),
3032 });
3133 final Text text;
32- final double padding; //! TODO: fix text not being centered
34+ final EdgeInsets padding; //! TODO: fix text not being centered
3335 final Color bubbleColor;
3436 final double borderRadius;
3537 final BubbleBoxTip tip;
@@ -48,11 +50,13 @@ class BubbleBoxPainter extends CustomPainter {
4850 )..layout ();
4951
5052 final textWidth = textPainter.width;
53+ final availableWidth = min (textWidth, size.width);
5154 final textHeight = textPainter.height;
55+ final availableHeight = max (textHeight, size.height);
5256
5357 // Calculate bubble size
54- final bubbleWidth = textWidth + padding * 2 ;
55- final bubbleHeight = textHeight + padding * 2 ;
58+ final bubbleWidth = availableWidth + padding.horizontal ;
59+ final bubbleHeight = availableHeight + padding.vertical ;
5660
5761 // Calculate tail size
5862 //! TODO: extract
@@ -61,16 +65,16 @@ class BubbleBoxPainter extends CustomPainter {
6165 final path = Path ()
6266
6367 // Top left corner
64- ..moveTo (0 , borderRadius)
65- ..quadraticBezierTo (0 , 0 , borderRadius, 0 )
68+ ..moveTo (0 - padding.left , borderRadius - padding.top )
69+ ..quadraticBezierTo (0 - padding.left , 0 - padding.top , borderRadius - padding.left , 0 - padding.top )
6670
6771 // Top right corner
68- ..lineTo (bubbleWidth - borderRadius, 0 )
69- ..quadraticBezierTo (bubbleWidth, 0 , bubbleWidth, borderRadius)
72+ ..lineTo (bubbleWidth - borderRadius - padding.left , 0 - padding.top )
73+ ..quadraticBezierTo (bubbleWidth - padding.left , 0 - padding.top , bubbleWidth - padding.left , borderRadius - padding.top )
7074
7175 // Bottom right corner
72- ..lineTo (bubbleWidth, bubbleHeight - borderRadius)
73- ..quadraticBezierTo (bubbleWidth, bubbleHeight, bubbleWidth - borderRadius, bubbleHeight);
76+ ..lineTo (bubbleWidth - padding.left , bubbleHeight - borderRadius - padding.top )
77+ ..quadraticBezierTo (bubbleWidth - padding.left , bubbleHeight - padding.top , bubbleWidth - borderRadius - padding.left , bubbleHeight - padding.top );
7478
7579 final tipOffset = bubbleWidth * 0.05 ;
7680
@@ -84,11 +88,11 @@ class BubbleBoxPainter extends CustomPainter {
8488
8589 // Bottom left corner with tail
8690 path
87- ..lineTo (tipStart, bubbleHeight)
88- ..lineTo (tipPeak, bubbleHeight + tailHeight)
89- ..lineTo (tipEnd, bubbleHeight)
90- ..lineTo (borderRadius, bubbleHeight)
91- ..quadraticBezierTo (0 , bubbleHeight, 0 , bubbleHeight - borderRadius)
91+ ..lineTo (tipStart, bubbleHeight - padding.top )
92+ ..lineTo (tipPeak, bubbleHeight + tailHeight - padding.top )
93+ ..lineTo (tipEnd, bubbleHeight - padding.top )
94+ ..lineTo (borderRadius - padding.left , bubbleHeight - padding.top )
95+ ..quadraticBezierTo (0 - padding.left , bubbleHeight - padding.top , 0 - padding.left , bubbleHeight - borderRadius - padding.top )
9296 ..close ();
9397
9498 // Draw the bubble
0 commit comments