Skip to content

Commit

Permalink
fix: Tooltip corruption in Segment and BarChartRod on update() (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ndonkoHenri authored and FeodorFitsner committed Dec 12, 2024
1 parent ecca747 commit 1adf160
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
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

0 comments on commit 1adf160

Please sign in to comment.