From 1adf16098b9e81265d2980b1afa26aff8adb93d7 Mon Sep 17 00:00:00 2001 From: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:32:55 +0100 Subject: [PATCH] fix: Tooltip corruption in `Segment` and `BarChartRod` on `update()` (#4525) * avoid jsonDecoding `Segment` and `BarChartRod` tooltips * avoid jsonEncoding `Segment` and `BarChartRod` tooltips * Unset theme visual density default * Unset `SegmentedButton` border side default * `TextField.hint_text` should be displayed if `label` is not specified --- packages/flet/lib/src/controls/barchart.dart | 5 ++--- packages/flet/lib/src/controls/segmented_button.dart | 5 +---- packages/flet/lib/src/utils/form_field.dart | 4 +++- .../packages/flet/src/flet/core/charts/bar_chart_rod.py | 2 +- sdk/python/packages/flet/src/flet/core/control.py | 6 ++++-- sdk/python/packages/flet/src/flet/core/theme.py | 4 +--- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/flet/lib/src/controls/barchart.dart b/packages/flet/lib/src/controls/barchart.dart index f3f3f2e01..ae585a451 100644 --- a/packages/flet/lib/src/controls/barchart.dart +++ b/packages/flet/lib/src/controls/barchart.dart @@ -263,9 +263,8 @@ class _BarChartControlState extends State { 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(); diff --git a/packages/flet/lib/src/controls/segmented_button.dart b/packages/flet/lib/src/controls/segmented_button.dart index 35763d530..f838c9288 100644 --- a/packages/flet/lib/src/controls/segmented_button.dart +++ b/packages/flet/lib/src/controls/segmented_button.dart @@ -49,7 +49,6 @@ class _SegmentedButtonControlState extends State 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))); @@ -124,9 +123,7 @@ class _SegmentedButtonControlState extends State 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) diff --git a/packages/flet/lib/src/utils/form_field.dart b/packages/flet/lib/src/utils/form_field.dart index 720dc5816..b476ee1f1 100644 --- a/packages/flet/lib/src/utils/form_field.dart +++ b/packages/flet/lib/src/utils/form_field.dart @@ -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, diff --git a/sdk/python/packages/flet/src/flet/core/charts/bar_chart_rod.py b/sdk/python/packages/flet/src/flet/core/charts/bar_chart_rod.py index d0728f25f..48c99f724 100644 --- a/sdk/python/packages/flet/src/flet/core/charts/bar_chart_rod.py +++ b/sdk/python/packages/flet/src/flet/core/charts/bar_chart_rod.py @@ -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() diff --git a/sdk/python/packages/flet/src/flet/core/control.py b/sdk/python/packages/flet/src/flet/core/control.py index 142bb31ba..cb2514d0e 100644 --- a/sdk/python/packages/flet/src/flet/core/control.py +++ b/sdk/python/packages/flet/src/flet/core/control.py @@ -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 diff --git a/sdk/python/packages/flet/src/flet/core/theme.py b/sdk/python/packages/flet/src/flet/core/theme.py index e9a0711d4..f8ce4b0b8 100644 --- a/sdk/python/packages/flet/src/flet/core/theme.py +++ b/sdk/python/packages/flet/src/flet/core/theme.py @@ -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