Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
implemented TapUp within InkResponse and InkWell (#93833)
Browse files Browse the repository at this point in the history
* implemented TapUp within InkResponse and InkWell

* Update packages/flutter/lib/src/material/ink_well.dart

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>

* Update packages/flutter/lib/src/material/ink_well.dart

Co-authored-by: Viren Khatri <werainkhatri.work@gmail.com>

* Update packages/flutter/lib/src/material/ink_well.dart

Co-authored-by: Viren Khatri <werainkhatri.work@gmail.com>

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Co-authored-by: Viren Khatri <werainkhatri.work@gmail.com>
  • Loading branch information
3 people authored Feb 9, 2022
1 parent 3bdea6b commit ae3f99c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/flutter/lib/src/material/ink_well.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class InkResponse extends StatelessWidget {
this.child,
this.onTap,
this.onTapDown,
this.onTapUp,
this.onTapCancel,
this.onDoubleTap,
this.onLongPress,
Expand Down Expand Up @@ -337,6 +338,10 @@ class InkResponse extends StatelessWidget {
/// Called when the user taps down this part of the material.
final GestureTapDownCallback? onTapDown;

/// Called when the user releases a tap that was started on this part of the
/// material. [onTap] is called immediately after.
final GestureTapUpCallback? onTapUp;

/// Called when the user cancels a tap that was started on this part of the
/// material.
final GestureTapCallback? onTapCancel;
Expand Down Expand Up @@ -583,6 +588,7 @@ class InkResponse extends StatelessWidget {
return _InkResponseStateWidget(
onTap: onTap,
onTapDown: onTapDown,
onTapUp: onTapUp,
onTapCancel: onTapCancel,
onDoubleTap: onDoubleTap,
onLongPress: onLongPress,
Expand Down Expand Up @@ -633,6 +639,7 @@ class _InkResponseStateWidget extends StatefulWidget {
this.child,
this.onTap,
this.onTapDown,
this.onTapUp,
this.onTapCancel,
this.onDoubleTap,
this.onLongPress,
Expand Down Expand Up @@ -669,6 +676,7 @@ class _InkResponseStateWidget extends StatefulWidget {
final Widget? child;
final GestureTapCallback? onTap;
final GestureTapDownCallback? onTapDown;
final GestureTapUpCallback? onTapUp;
final GestureTapCallback? onTapCancel;
final GestureTapCallback? onDoubleTap;
final GestureLongPressCallback? onLongPress;
Expand Down Expand Up @@ -707,6 +715,7 @@ class _InkResponseStateWidget extends StatefulWidget {
if (onDoubleTap != null) 'double tap',
if (onLongPress != null) 'long press',
if (onTapDown != null) 'tap down',
if (onTapUp != null) 'tap up',
if (onTapCancel != null) 'tap cancel',
];
properties.add(IterableProperty<String>('gestures', gestures, ifEmpty: '<none>'));
Expand Down Expand Up @@ -963,6 +972,10 @@ class _InkResponseState extends State<_InkResponseStateWidget>
widget.onTapDown?.call(details);
}

void _handleTapUp(TapUpDetails details) {
widget.onTapUp?.call(details);
}

void _startSplash({TapDownDetails? details, BuildContext? context}) {
assert(details != null || context != null);

Expand Down Expand Up @@ -1106,6 +1119,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
onLongPress: widget.excludeFromSemantics || widget.onLongPress == null ? null : _simulateLongPress,
child: GestureDetector(
onTapDown: enabled ? _handleTapDown : null,
onTapUp: enabled ? _handleTapUp : null,
onTap: enabled ? _handleTap : null,
onTapCancel: enabled ? _handleTapCancel : null,
onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null,
Expand Down Expand Up @@ -1214,6 +1228,7 @@ class InkWell extends InkResponse {
GestureTapCallback? onDoubleTap,
GestureLongPressCallback? onLongPress,
GestureTapDownCallback? onTapDown,
GestureTapUpCallback? onTapUp,
GestureTapCancelCallback? onTapCancel,
ValueChanged<bool>? onHighlightChanged,
ValueChanged<bool>? onHover,
Expand All @@ -1240,6 +1255,7 @@ class InkWell extends InkResponse {
onDoubleTap: onDoubleTap,
onLongPress: onLongPress,
onTapDown: onTapDown,
onTapUp: onTapUp,
onTapCancel: onTapCancel,
onHighlightChanged: onHighlightChanged,
onHover: onHover,
Expand Down
6 changes: 5 additions & 1 deletion packages/flutter/test/material/ink_well_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void main() {
onTapDown: (TapDownDetails details) {
log.add('tap-down');
},
onTapUp: (TapUpDetails details) {
log.add('tap-up');
},
onTapCancel: () {
log.add('tap-cancel');
},
Expand All @@ -47,7 +50,7 @@ void main() {

await tester.pump(const Duration(seconds: 1));

expect(log, equals(<String>['tap-down', 'tap']));
expect(log, equals(<String>['tap-down', 'tap-up', 'tap']));
log.clear();

await tester.tap(find.byType(InkWell), pointer: 2);
Expand All @@ -67,6 +70,7 @@ void main() {
expect(log, equals(<String>['tap-down']));
await gesture.up();
await tester.pump(const Duration(seconds: 1));
expect(log, equals(<String>['tap-down', 'tap-up', 'tap']));

log.clear();
gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
Expand Down

0 comments on commit ae3f99c

Please sign in to comment.