Search code examples
flutterflutter-layouttooltip

Crate custom tail in just_the_tooltip Library


I am using JustTheTooltip library. There is a built in function to create a custom tail, but I can't figure out how to create the path relative to the tooltip. I need a custom triangle to the left.

Docs:

Tail Builder If you'd like a custom tail (the nub on the end dialog bubble) drawn on your tooltip, you can pass through your own

tailBuilder. The JustTheInterface.defaultTailBuilder (default) shows how to simply draw and return a path for your custom tails:

Path defaultTailBuilder(Offset tip, Offset point2, Offset point3) {
return Path() ..moveTo(tip.dx, tip.dy) ..lineTo(point2.dx, point2.dy) ..lineTo(point3.dx, point3.dy) ..close(); }

I am trying this:

JustTheTooltip(
  preferredDirection: AxisDirection.right,
  tailBuilder: (_, __, ___) => _customTailBuilder(Offset(100, 100), Offset(170, 150), Offset(170, 50),),
  ................
);

And _customTailBuilder is the same as above, in the docs.

Path _customTailBuilder(Offset tip, Offset point2, Offset point3) {  
 return Path()
     ..moveTo(tip.dx, tip.dy)
     ..lineTo(point2.dx, point2.dy)
     ..lineTo(point3.dx, point3.dy)
     ..close(); 
}

I need the triangle to be relative to the tooltip, I don't know how to get the postition, thank you


Solution

  • This is what I have done.

      Path defaultTailBuilder(Offset tip, Offset point2, Offset point3) {
    Size size = MediaQuery.of(context).size;
    
        return Path()
          ..moveTo(tip.dx + size - 100, tip.dy)
          ..lineTo(point2.dx + size - 100, point2.dy)
          ..lineTo(point3.dx + size - 100, point3.dy)
          ..close();
      }