Skip to content

Commit 9297ce6

Browse files
committed
Make MouseRegion as the child of GestureDetector to ensure that the gesture events can be detected correctly when the cursor has changed (e.g. click)
1 parent f4693d4 commit 9297ce6

21 files changed

Lines changed: 218 additions & 231 deletions

File tree

turms-chat-demo-flutter/lib/ui/desktop/components/giphy/giphy_picker.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ class _GiphyPickerBodyState extends ConsumerState<GiphyPickerBody> {
116116
final url = image.url;
117117
return ClipRRect(
118118
borderRadius: Sizes.borderRadiusCircular8,
119-
child: MouseRegion(
120-
cursor: SystemMouseCursors.click,
121-
child: GestureDetector(
122-
onTap: () => widget.onSelected(gif),
119+
child: GestureDetector(
120+
onTap: () => widget.onSelected(gif),
121+
child: MouseRegion(
122+
cursor: SystemMouseCursors.click,
123123
child: RepaintBoundary(
124124
child: LayoutBuilder(
125125
builder: (context, constraints) {

turms-chat-demo-flutter/lib/ui/desktop/components/t_accordion/t_accordion.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ class _TAccordionState extends State<TAccordion>
115115
Widget build(BuildContext context) => Column(
116116
crossAxisAlignment: CrossAxisAlignment.start,
117117
children: [
118-
MouseRegion(
119-
cursor: SystemMouseCursors.click,
120-
child: GestureDetector(
121-
onTap: _toggleCollapsed,
118+
GestureDetector(
119+
onTap: _toggleCollapsed,
120+
child: MouseRegion(
121+
cursor: SystemMouseCursors.click,
122122
child: DecoratedBox(
123123
decoration: BoxDecoration(
124124
borderRadius: widget.titleBorderRadius,

turms-chat-demo-flutter/lib/ui/desktop/components/t_button/t_button.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,26 @@ class _TButtonState extends State<TButton> {
153153
);
154154
}
155155
return RepaintBoundary(
156-
child: MouseRegion(
157-
cursor: widget.disabled
158-
? SystemMouseCursors.forbidden
159-
: SystemMouseCursors.click,
160-
onEnter: (_) {
161-
_isHovered = true;
156+
child: GestureDetector(
157+
onTap: !widget.disabled && !widget.isLoading && widget.onTap != null
158+
? widget.onTap
159+
: null,
160+
onPanDown: (details) {
161+
_isPressed = true;
162+
widget.onPanDown?.call(details);
162163
setState(() {});
163164
},
164-
onExit: (_) {
165-
_isHovered = false;
166-
_isPressed = false;
167-
setState(() {});
168-
},
169-
child: GestureDetector(
170-
onTap: !widget.disabled && !widget.isLoading && widget.onTap != null
171-
? widget.onTap
172-
: null,
173-
onPanDown: (details) {
174-
_isPressed = true;
175-
widget.onPanDown?.call(details);
165+
child: MouseRegion(
166+
cursor: widget.disabled
167+
? SystemMouseCursors.forbidden
168+
: SystemMouseCursors.click,
169+
onEnter: (_) {
170+
_isHovered = true;
171+
setState(() {});
172+
},
173+
onExit: (_) {
174+
_isHovered = false;
175+
_isPressed = false;
176176
setState(() {});
177177
},
178178
child: child,

turms-chat-demo-flutter/lib/ui/desktop/components/t_checkbox/t_checkbox.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class _TCheckboxState extends State<TCheckbox> {
2727
_isChecked ??= widget.initialValue;
2828
final isChecked = _isChecked!;
2929
final appThemeExtension = context.appThemeExtension;
30-
return MouseRegion(
31-
cursor: SystemMouseCursors.click,
32-
child: GestureDetector(
33-
onTap: () {
34-
_isChecked = !isChecked;
35-
widget.onCheckedChanged(isChecked);
36-
setState(() {});
37-
},
30+
return GestureDetector(
31+
onTap: () {
32+
_isChecked = !isChecked;
33+
widget.onCheckedChanged(isChecked);
34+
setState(() {});
35+
},
36+
child: MouseRegion(
37+
cursor: SystemMouseCursors.click,
3838
child: Row(
3939
spacing: 4,
4040
mainAxisSize: MainAxisSize.min,

turms-chat-demo-flutter/lib/ui/desktop/components/t_checkbox/t_simple_checkbox.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ class _TSimpleCheckboxState extends State<TSimpleCheckbox> {
7878
children: [child, Text(label)],
7979
);
8080
}
81-
return MouseRegion(
82-
cursor: SystemMouseCursors.click,
83-
child: GestureDetector(
84-
onTap: () {
85-
widget.onChanged(!widget.value);
86-
},
87-
child: child,
88-
),
81+
return GestureDetector(
82+
onTap: () {
83+
widget.onChanged(!widget.value);
84+
},
85+
child: MouseRegion(cursor: SystemMouseCursors.click, child: child),
8986
);
9087
}
9188
}

turms-chat-demo-flutter/lib/ui/desktop/components/t_date_picker/t_date_cell.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,34 +211,34 @@ class _TDateCellState extends ConsumerState<TDateCell> {
211211
],
212212
);
213213
}
214-
return MouseRegion(
215-
cursor: disabled
216-
? SystemMouseCursors.forbidden
217-
: SystemMouseCursors.click,
218-
onEnter: (event) {
214+
return GestureDetector(
215+
onTap: () {
219216
if (!disabled) {
220-
setState(() {
221-
_isHovered = true;
222-
});
223-
if (widget.inCurrentCalendarMonth) {
224-
widget.onMouseRegionEntered?.call(widget.date);
225-
}
217+
widget.onTap(widget.date);
226218
}
227219
},
228-
onExit: (event) {
229-
if (!disabled) {
230-
setState(() {
231-
_isHovered = false;
232-
});
233-
if (widget.inCurrentCalendarMonth) {
234-
widget.onMouseRegionExited?.call(widget.date);
220+
child: MouseRegion(
221+
cursor: disabled
222+
? SystemMouseCursors.forbidden
223+
: SystemMouseCursors.click,
224+
onEnter: (event) {
225+
if (!disabled) {
226+
setState(() {
227+
_isHovered = true;
228+
});
229+
if (widget.inCurrentCalendarMonth) {
230+
widget.onMouseRegionEntered?.call(widget.date);
231+
}
235232
}
236-
}
237-
},
238-
child: GestureDetector(
239-
onTap: () {
233+
},
234+
onExit: (event) {
240235
if (!disabled) {
241-
widget.onTap(widget.date);
236+
setState(() {
237+
_isHovered = false;
238+
});
239+
if (widget.inCurrentCalendarMonth) {
240+
widget.onMouseRegionExited?.call(widget.date);
241+
}
242242
}
243243
},
244244
child: TTooltip(

turms-chat-demo-flutter/lib/ui/desktop/components/t_image_cropper/t_image_cropper.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ extension _ImageCropperStateView on _ImageCropperState {
436436
Positioned(
437437
left: cropRect.left,
438438
top: cropRect.top,
439-
child: MouseRegion(
440-
cursor: SystemMouseCursors.move,
441-
child: GestureDetector(
442-
onPanUpdate: (details) =>
443-
_updateCropRect(_data!.moveRect(details.delta)),
439+
child: GestureDetector(
440+
onPanUpdate: (details) =>
441+
_updateCropRect(_data!.moveRect(details.delta)),
442+
child: MouseRegion(
443+
cursor: SystemMouseCursors.move,
444444
child: Container(
445445
width: cropRect.width,
446446
height: cropRect.height,

turms-chat-demo-flutter/lib/ui/desktop/components/t_list_tile/t_list_tile.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class _TListTileState extends State<TListTile> {
4141
@override
4242
Widget build(BuildContext context) {
4343
final appThemeExtension = context.appThemeExtension;
44-
return MouseRegion(
45-
cursor: widget.mouseCursor,
46-
onEnter: (_) => setState(() => _isHovered = true),
47-
onExit: (_) => setState(() => _isHovered = false),
48-
child: GestureDetector(
49-
onTap: widget.onTap,
50-
onSecondaryTapUp: widget.onSecondaryTapUp,
44+
return GestureDetector(
45+
onTap: widget.onTap,
46+
onSecondaryTapUp: widget.onSecondaryTapUp,
47+
child: MouseRegion(
48+
cursor: widget.mouseCursor,
49+
onEnter: (_) => setState(() => _isHovered = true),
50+
onExit: (_) => setState(() => _isHovered = false),
5151
child: AnimatedContainer(
5252
height: widget.height,
5353
alignment: Alignment.center,

turms-chat-demo-flutter/lib/ui/desktop/components/t_menu/t_menu.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,21 @@ class _TMenuState<T> extends State<TMenu<T>> {
161161
content = Row(spacing: 8, children: [prefix, content]);
162162
}
163163
content = Padding(padding: widget.padding, child: content);
164-
return MouseRegion(
165-
cursor: SystemMouseCursors.click,
166-
onEnter: (event) => setState(() {
167-
_hoveredEntryIndex = index;
168-
}),
169-
onExit: (event) => setState(() {
170-
if (_hoveredEntryIndex == index) {
171-
_hoveredEntryIndex = null;
172-
}
173-
}),
174-
child: GestureDetector(
175-
behavior: HitTestBehavior.translucent,
176-
onTap: () {
177-
_select(entry);
178-
},
164+
return GestureDetector(
165+
behavior: HitTestBehavior.translucent,
166+
onTap: () {
167+
_select(entry);
168+
},
169+
child: MouseRegion(
170+
cursor: SystemMouseCursors.click,
171+
onEnter: (event) => setState(() {
172+
_hoveredEntryIndex = index;
173+
}),
174+
onExit: (event) => setState(() {
175+
if (_hoveredEntryIndex == index) {
176+
_hoveredEntryIndex = null;
177+
}
178+
}),
179179
child: ColoredBox(
180180
color: _hoveredEntryIndex == index
181181
? appThemeExtension.menuItemHoveredColor

turms-chat-demo-flutter/lib/ui/desktop/components/t_popup/t_popup.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class _TPopupState extends State<TPopup> {
7171
}
7272

7373
@override
74-
Widget build(BuildContext context) => MouseRegion(
75-
cursor: SystemMouseCursors.click,
76-
child: GestureDetector(
77-
behavior: HitTestBehavior.opaque,
78-
key: _targetKey,
79-
onTap: _togglePopup,
74+
Widget build(BuildContext context) => GestureDetector(
75+
behavior: HitTestBehavior.opaque,
76+
key: _targetKey,
77+
onTap: _togglePopup,
78+
child: MouseRegion(
79+
cursor: SystemMouseCursors.click,
8080
child: CompositedTransformTarget(link: _layerLink, child: widget.target),
8181
),
8282
);

0 commit comments

Comments
 (0)