Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/bartooltip item with text span children #554

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,21 @@ class BarTooltipItem with EquatableMixin {
/// TextStyle of the showing content.
final TextStyle textStyle;

/// List<InlineSpan> for more flexibility in showing content.
final List<InlineSpan> children;

/// content of the tooltip, is a [text] String with a [textStyle].
BarTooltipItem(String text, TextStyle textStyle)
BarTooltipItem(String text, TextStyle textStyle, [List<InlineSpan> children])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you put List around [ ] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i figured this is the easiest way to do it without breaking any compatibility. could have also done named. i have no preference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you can still call BarTooltipItem('something', TextStyle(fontSize: 12)) with no issue

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay please change it to named parameter.
Also, it will be great if you do the same in LineTooltipItem, and ScatterTooltipItem.

: text = text,
textStyle = textStyle;
textStyle = textStyle,
children = children;

/// Used for equality check, see [EquatableMixin].
@override
List<Object> get props => [
text,
textStyle,
children,
];
}

Expand Down
7 changes: 6 additions & 1 deletion lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@ class BarChartPainter extends AxisChartPainter<BarChartData> with TouchHandler<B
return;
}

final span = TextSpan(style: tooltipItem.textStyle, text: tooltipItem.text);
final span = TextSpan(
style: tooltipItem.textStyle,
text: tooltipItem.text,
children: tooltipItem.children,
);

final tp = TextPainter(
text: span,
textAlign: TextAlign.center,
Expand Down