Skip to content
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
32 changes: 13 additions & 19 deletions packages/flet/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../models/control_view_model.dart';
import '../models/page_media_view_model.dart';
import '../utils/animations.dart';
import '../utils/theme.dart';
import '../utils/tooltip.dart';
import '../utils/transforms.dart';
import 'alert_dialog.dart';
import 'animated_switcher.dart';
Expand Down Expand Up @@ -112,7 +113,6 @@ import 'text.dart';
import 'text_button.dart';
import 'textfield.dart';
import 'time_picker.dart';
import 'tooltip.dart';
import 'transparent_pointer.dart';
import 'vertical_divider.dart';
import 'window_drag_area.dart';
Expand Down Expand Up @@ -448,7 +448,7 @@ Widget createWidget(
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive,
backend: backend);
case "placeholder":
case "placeholder":
return PlaceholderControl(
key: key,
parent: parent,
Expand Down Expand Up @@ -592,14 +592,6 @@ Widget createWidget(
children: controlView.children,
parentDisabled: parentDisabled,
backend: backend);
case "tooltip":
return TooltipControl(
key: key,
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive);
case "transparentpointer":
return TransparentPointerControl(
key: key,
Expand Down Expand Up @@ -1017,7 +1009,12 @@ Widget baseControl(
BuildContext context, Widget widget, Control? parent, Control control) {
return _expandable(
_directionality(
_tooltip(_opacity(context, widget, parent, control), parent, control),
_tooltip(
_opacity(context, widget, parent, control),
Theme.of(context),
parent,
control,
),
parent,
control),
parent,
Expand All @@ -1041,6 +1038,7 @@ Widget constrainedControl(
_tooltip(
_opacity(
context, widget, parent, control),
Theme.of(context),
parent,
control),
parent,
Expand Down Expand Up @@ -1088,17 +1086,13 @@ Widget _opacity(
return widget;
}

Widget _tooltip(Widget widget, Control? parent, Control control) {
var tooltip = control.attrString("tooltip");
Widget _tooltip(
Widget widget, ThemeData theme, Control? parent, Control control) {
var tooltip = parseTooltip(control, "tooltip", widget, theme);
return tooltip != null &&
!["iconbutton", "floatingactionbutton", "popupmenubutton"]
.contains(control.type)
? Tooltip(
message: tooltip,
padding: const EdgeInsets.all(4.0),
waitDuration: const Duration(milliseconds: 800),
child: widget,
)
? tooltip
: widget;
}

Expand Down
85 changes: 0 additions & 85 deletions packages/flet/lib/src/controls/tooltip.dart

This file was deleted.

31 changes: 31 additions & 0 deletions packages/flet/lib/src/utils/time.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:convert';

import '../models/control.dart';
import 'numbers.dart';

Duration? parseDuration(Control control, String propName,
[Duration? defaultValue]) {
var v = control.attrString(propName, null);
if (v == null) {
return null;
}

final j1 = json.decode(v);
return durationFromJSON(j1);
}

Duration? durationFromJSON(dynamic json) {
if (json == null) {
return null;
}
if (json is int || json is double) {
return Duration(milliseconds: parseInt(json, 0)!);
}
return Duration(
days: parseInt(json["days"], 0)!,
hours: parseInt(json["hours"], 0)!,
minutes: parseInt(json["minutes"], 0)!,
seconds: parseInt(json["seconds"], 0)!,
milliseconds: parseInt(json["milliseconds"], 0)!,
microseconds: parseInt(json["microseconds"], 0)!);
}
79 changes: 79 additions & 0 deletions packages/flet/lib/src/utils/tooltip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';

import '../models/control.dart';
import 'borders.dart';
import 'box.dart';
import 'colors.dart';
import 'edge_insets.dart';
import 'gradient.dart';
import 'images.dart';
import 'numbers.dart';
import 'others.dart';
import 'text.dart';
import 'time.dart';

TooltipTriggerMode? parseTooltipTriggerMode(String? value,
[TooltipTriggerMode? defaultValue]) {
if (value == null) {
return defaultValue;
}
return TooltipTriggerMode.values.firstWhereOrNull(
(e) => e.name.toLowerCase() == value.toLowerCase()) ??
defaultValue;
}

Tooltip? parseTooltip(
Control control, String propName, Widget widget, ThemeData theme) {
var v = control.attrString(propName, null);
if (v == null) {
return null;
}
final j = json.decode(v);
return tooltipFromJSON(j, widget, theme);
}

Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Add documentation for the expected JSON structure

Please add a comment explaining the expected JSON structure for this function. This will help developers correctly format their tooltip data.

Suggested change
Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) {
/// Converts a JSON object to a Tooltip widget.
/// Expected JSON structure:
/// {
/// "message": "Tooltip text",
/// "preferBelow": true,
/// "verticalOffset": 20.0
/// }
Tooltip? tooltipFromJSON(dynamic j, Widget widget, ThemeData theme) {

if (j == null) {
return null;
} else if (j is String) {
return Tooltip(
message: j,
padding: const EdgeInsets.all(4.0),
waitDuration: const Duration(milliseconds: 800),
child: widget,
);
}
var decoration = boxDecorationFromDetails(
gradient: gradientFromJSON(theme, j["gradient"]),
border: borderFromJSON(theme, j["border"]),
borderRadius: borderRadiusFromJSON(j["border_radius"]),
shape: parseBoxShape(j["shape"]),
color: parseColor(theme, j["bgcolor"]),
blendMode: parseBlendMode(j["blend_mode"]),
boxShadow: boxShadowsFromJSON(theme, j["box_shadow"]),
image: decorationImageFromJSON(
theme, j["image"], null), // TODO: pass correct pageArgs
);
return Tooltip(
message: j["message"],
enableFeedback: parseBool(j["enable_feedback"]),
enableTapToDismiss: parseBool(j["enable_tap_to_dismiss"], true)!,
excludeFromSemantics: parseBool(j["exclude_from_semantics"]),
height: parseDouble(j["height"]),
exitDuration: durationFromJSON(j["exit_duration"]),
preferBelow: parseBool(j["prefer_below"]),
padding: edgeInsetsFromJson(j["padding"]),
decoration: decoration,
textStyle: textStyleFromJson(theme, j["text_style"]),
verticalOffset: parseDouble(j["vertical_offset"]),
margin: edgeInsetsFromJson(j["margin"]),
textAlign: parseTextAlign(j["text_align"]),
showDuration: durationFromJSON(j["show_duration"]),
waitDuration: durationFromJSON(j["wait_duration"]),
triggerMode: parseTooltipTriggerMode(j["trigger_mode"]),
child: widget,
);
}
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
TimePickerEntryMode,
TimePickerEntryModeChangeEvent,
)
from flet_core.tooltip import Tooltip
from flet_core.tooltip import Tooltip, TooltipTriggerMode
from flet_core.transform import Offset, Rotate, Scale
from flet_core.transparent_pointer import TransparentPointer
from flet_core.types import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flet_core.constrained_control import ConstrainedControl
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
OffsetValue,
Expand Down Expand Up @@ -111,7 +112,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flet_core.constrained_control import ConstrainedControl
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
ClipBehavior,
Expand Down Expand Up @@ -105,7 +106,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from flet_core.control_event import ControlEvent
from flet_core.event_handler import EventHandler
from flet_core.ref import Ref
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
OffsetValue,
Expand Down Expand Up @@ -84,7 +85,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from flet_core.control_event import ControlEvent
from flet_core.event_handler import EventHandler
from flet_core.ref import Ref
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
OffsetValue,
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flet_core.control_event import ControlEvent
from flet_core.event_handler import EventHandler
from flet_core.ref import Ref
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
OffsetValue,
Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flet_core.control import OptionalNumber
from flet_core.ref import Ref
from flet_core.text_style import TextStyle
from flet_core.tooltip import TooltipValue
from flet_core.types import (
AnimationValue,
LabelPosition,
Expand Down Expand Up @@ -106,7 +107,7 @@ def __init__(
animate_scale: AnimationValue = None,
animate_offset: AnimationValue = None,
on_animation_end: OptionalControlEventCallable = None,
tooltip: Optional[str] = None,
tooltip: TooltipValue = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
Expand Down
Loading