Skip to content

Commit 506d995

Browse files
authored
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
1 parent c5301e5 commit 506d995

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

packages/flet/lib/src/controls/barchart.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,8 @@ class _BarChartControlState extends State<BarChartControl> {
263263
getTooltipItem: (group, groupIndex, rod, rodIndex) {
264264
var dp = viewModel.barGroups[groupIndex].barRods[rodIndex];
265265

266-
var tooltip = dp.control.attrString("tooltip") != null
267-
? jsonDecode(dp.control.attrString("tooltip")!)
268-
: dp.control.attrDouble("toY", 0)!.toString();
266+
var tooltip = dp.control.attrString("tooltip",
267+
dp.control.attrDouble("toY", 0)!.toString())!;
269268
var tooltipStyle = parseTextStyle(
270269
Theme.of(context), dp.control, "tooltipStyle");
271270
tooltipStyle ??= const TextStyle();

packages/flet/lib/src/controls/segmented_button.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class _SegmentedButtonControlState extends State<SegmentedButtonControl>
4949
defaultSurfaceTintColor: theme.colorScheme.surfaceTint,
5050
defaultElevation: 1,
5151
defaultPadding: const EdgeInsets.symmetric(horizontal: 8),
52-
defaultBorderSide: BorderSide.none,
5352
defaultShape: theme.useMaterial3
5453
? const StadiumBorder()
5554
: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
@@ -124,9 +123,7 @@ class _SegmentedButtonControlState extends State<SegmentedButtonControl>
124123
return ButtonSegment(
125124
value: segmentView.control.attrString("value")!,
126125
enabled: !segmentDisabled,
127-
tooltip: !segmentDisabled && segmentTooltip != null
128-
? jsonDecode(segmentTooltip)
129-
: null,
126+
tooltip: segmentDisabled ? null : segmentTooltip,
130127
icon: iconCtrls.isNotEmpty
131128
? createControl(segmentView.control, iconCtrls.first.id,
132129
segmentDisabled)

packages/flet/lib/src/utils/form_field.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ InputDecoration buildInputDecoration(BuildContext context, Control control,
154154
label: label != null
155155
? createControl(control, label.id, control.isDisabled,
156156
parentAdaptive: adaptive)
157-
: Text(control.attrString("label", "")!),
157+
: control.attrString("label") != null
158+
? Text(control.attrString("label")!)
159+
: null,
158160
labelStyle: parseTextStyle(Theme.of(context), control, "labelStyle"),
159161
border: border,
160162
enabledBorder: border,

sdk/python/packages/flet/src/flet/core/charts/bar_chart_rod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
self.tooltip_style = tooltip_style
6969

7070
def _get_control_name(self):
71-
return "rod"
71+
return "bar_chart_rod"
7272

7373
def before_update(self):
7474
super().before_update()

sdk/python/packages/flet/src/flet/core/control.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ def before_update(self):
9191
pass
9292

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

99101
def did_mount(self):
100102
pass

sdk/python/packages/flet/src/flet/core/theme.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,4 @@ class Theme:
888888
text_theme: Optional[TextTheme] = None
889889
time_picker_theme: Optional[TimePickerTheme] = None
890890
tooltip_theme: Optional[TooltipTheme] = None
891-
visual_density: Union[VisualDensity, ThemeVisualDensity] = field(
892-
default=VisualDensity.STANDARD
893-
)
891+
visual_density: Union[VisualDensity, ThemeVisualDensity] = None

0 commit comments

Comments
 (0)