Skip to content

Commit c1c063f

Browse files
authored
Fix triggered both on_click and on_long_press events (#2914)
1 parent c8ab1ab commit c1c063f

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,16 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
153153
// Dummy callback to enable widget
154154
// see https://github.com/flutter/flutter/issues/50116#issuecomment-582047374
155155
// and https://github.com/flutter/flutter/blob/eed80afe2c641fb14b82a22279d2d78c19661787/packages/flutter/lib/src/material/ink_well.dart#L1125-L1129
156-
onTap: onHover ? () {} : null,
157-
onTapDown: onClick || url != ""
158-
? (details) {
156+
onTap: onClick || url != ""
157+
? () {
159158
debugPrint("Container ${control.id} clicked!");
160159
if (url != "") {
161160
openWebBrowser(url, webWindowName: urlTarget);
162161
}
163162
if (onClick) {
164163
backend.triggerControlEvent(
165164
control.id,
166-
"click",
167-
json.encode(ContainerTapEvent(
168-
localX: details.localPosition.dx,
169-
localY: details.localPosition.dy,
170-
globalX: details.globalPosition.dx,
171-
globalY: details.globalPosition.dy)
172-
.toJson()));
165+
"click");
173166
}
174167
}
175168
: null,
@@ -201,7 +194,7 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
201194
width: control.attrDouble("width"),
202195
height: control.attrDouble("height"),
203196
margin: parseEdgeInsets(control, "margin"),
204-
clipBehavior: Clip.none,
197+
clipBehavior: clipBehavior,
205198
decoration: boxDecor,
206199
child: ink,
207200
)
@@ -269,22 +262,16 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
269262
}
270263
: null,
271264
child: GestureDetector(
272-
onTapDown: onClick || url != ""
273-
? (details) {
265+
onTap: onClick || url != ""
266+
? () {
274267
debugPrint("Container ${control.id} clicked!");
275268
if (url != "") {
276269
openWebBrowser(url, webWindowName: urlTarget);
277270
}
278271
if (onClick) {
279272
backend.triggerControlEvent(
280273
control.id,
281-
"click",
282-
json.encode(ContainerTapEvent(
283-
localX: details.localPosition.dx,
284-
localY: details.localPosition.dy,
285-
globalX: details.globalPosition.dx,
286-
globalY: details.globalPosition.dy)
287-
.toJson()));
274+
"click");
288275
}
289276
}
290277
: null,

sdk/python/packages/flet-core/src/flet_core/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,11 @@ def theme_mode(self, value: Optional[ThemeMode]):
474474
# on_click
475475
@property
476476
def on_click(self):
477-
return self.__on_click
477+
return self._get_event_handler("click")
478478

479479
@on_click.setter
480480
def on_click(self, handler):
481-
self.__on_click.subscribe(handler)
481+
self._add_event_handler("click", handler)
482482
self._set_attr("onClick", True if handler is not None else None)
483483

484484
# on_long_press

0 commit comments

Comments
 (0)