lab_overflow_tooltip_wrapper.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:flyinsono/lab/components/lab_text_tool_tip.dart';
  2. import 'package:flutter/material.dart';
  3. class LabOverflowTooltipWrapper extends StatelessWidget {
  4. final Text child;
  5. final DisplayPosition position;
  6. final Offset offset;
  7. LabOverflowTooltipWrapper({
  8. Key? key,
  9. required this.child,
  10. this.position = DisplayPosition.top,
  11. this.offset = const Offset(0, -3),
  12. }) : assert(
  13. child.style != null && child.style!.fontFamily != null,
  14. 'child must have a non-null style with a non-null fontFamily',
  15. ),
  16. super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. var tp = TextPainter(
  20. maxLines: child.maxLines,
  21. textAlign: child.textAlign ?? TextAlign.start,
  22. textDirection: child.textDirection ?? TextDirection.ltr,
  23. text: child.textSpan ??
  24. TextSpan(
  25. text: child.data,
  26. style: child.style,
  27. ),
  28. );
  29. return LayoutBuilder(
  30. builder: (context, constrains) {
  31. tp.layout(maxWidth: constrains.maxWidth);
  32. final overflowed = tp.didExceedMaxLines;
  33. if (overflowed) {
  34. return LabTextTooltip(
  35. position: position,
  36. offset: offset,
  37. message: child.data ?? '',
  38. child: child,
  39. );
  40. }
  41. return child;
  42. },
  43. );
  44. }
  45. }