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

fix: Tooltip corruption in Segment and BarChartRod on update() #4525

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions packages/flet/lib/src/controls/barchart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ class _BarChartControlState extends State<BarChartControl> {
getTooltipItem: (group, groupIndex, rod, rodIndex) {
var dp = viewModel.barGroups[groupIndex].barRods[rodIndex];

var tooltip = dp.control.attrString("tooltip") != null
? jsonDecode(dp.control.attrString("tooltip")!)
: dp.control.attrDouble("toY", 0)!.toString();
var tooltip = dp.control.attrString("tooltip",
dp.control.attrDouble("toY", 0)!.toString())!;
var tooltipStyle = parseTextStyle(
Theme.of(context), dp.control, "tooltipStyle");
tooltipStyle ??= const TextStyle();
Expand Down
5 changes: 1 addition & 4 deletions packages/flet/lib/src/controls/segmented_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class _SegmentedButtonControlState extends State<SegmentedButtonControl>
defaultSurfaceTintColor: theme.colorScheme.surfaceTint,
defaultElevation: 1,
defaultPadding: const EdgeInsets.symmetric(horizontal: 8),
defaultBorderSide: BorderSide.none,
defaultShape: theme.useMaterial3
? const StadiumBorder()
: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
Expand Down Expand Up @@ -124,9 +123,7 @@ class _SegmentedButtonControlState extends State<SegmentedButtonControl>
return ButtonSegment(
value: segmentView.control.attrString("value")!,
enabled: !segmentDisabled,
tooltip: !segmentDisabled && segmentTooltip != null
? jsonDecode(segmentTooltip)
: null,
tooltip: segmentDisabled ? null : segmentTooltip,
icon: iconCtrls.isNotEmpty
? createControl(segmentView.control, iconCtrls.first.id,
segmentDisabled)
Expand Down
4 changes: 3 additions & 1 deletion packages/flet/lib/src/utils/form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ InputDecoration buildInputDecoration(BuildContext context, Control control,
label: label != null
? createControl(control, label.id, control.isDisabled,
parentAdaptive: adaptive)
: Text(control.attrString("label", "")!),
: control.attrString("label") != null
? Text(control.attrString("label")!)
: null,
labelStyle: parseTextStyle(Theme.of(context), control, "labelStyle"),
border: border,
enabledBorder: border,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self.tooltip_style = tooltip_style

def _get_control_name(self):
return "rod"
return "bar_chart_rod"

def before_update(self):
super().before_update()
Expand Down
6 changes: 4 additions & 2 deletions sdk/python/packages/flet/src/flet/core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ def before_update(self):
pass

def _before_build_command(self) -> None:
self._set_attr_json("col", self.__col)
self._set_attr_json("tooltip", self.tooltip)
if self._get_control_name() not in ["segment", "bar_chart_rod"]:
# see https://github.com/flet-dev/flet/pull/4525
self._set_attr_json("tooltip", self.tooltip)
if isinstance(self.badge, (Badge, str)):
self._set_attr_json("badge", self.badge)
self._set_attr_json("col", self.__col)

def did_mount(self):
pass
Expand Down
4 changes: 1 addition & 3 deletions sdk/python/packages/flet/src/flet/core/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,4 @@ class Theme:
text_theme: Optional[TextTheme] = None
time_picker_theme: Optional[TimePickerTheme] = None
tooltip_theme: Optional[TooltipTheme] = None
visual_density: Union[VisualDensity, ThemeVisualDensity] = field(
default=VisualDensity.STANDARD
)
visual_density: Union[VisualDensity, ThemeVisualDensity] = None