Skip to content

Commit

Permalink
refactor: Move custom gesture detector to common (MewsSystems#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
witwash authored Jun 14, 2024
1 parent 421a741 commit 57a9881
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
26 changes: 26 additions & 0 deletions optimus/lib/src/common/gesture_detector.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';

class AllowMultipleRawGestureDetector extends RawGestureDetector {
AllowMultipleRawGestureDetector({
super.key,
GestureTapCallback? onTap,
super.child,
}) : super(
behavior: HitTestBehavior.opaque,
gestures: <Type, GestureRecognizerFactory>{
AllowMultipleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
AllowMultipleGestureRecognizer>(
AllowMultipleGestureRecognizer.new,
(AllowMultipleGestureRecognizer instance) =>
instance.onTap = onTap,
),
},
);
}

class AllowMultipleGestureRecognizer extends TapGestureRecognizer {
@override
void rejectGesture(int pointer) => acceptGesture(pointer);
}
27 changes: 2 additions & 25 deletions optimus/lib/src/dropdown/dropdown_select.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:dfunc/dfunc.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:optimus/optimus.dart';
import 'package:optimus/src/common/gesture_detector.dart';
import 'package:optimus/src/dropdown/dropdown_tap_interceptor.dart';
import 'package:optimus/src/form/multiselect_field.dart';

Expand Down Expand Up @@ -422,7 +422,7 @@ class _ClearAllButton extends StatelessWidget {
final GestureTapCallback? onTap;

@override
Widget build(BuildContext context) => _CustomRawGestureDetector(
Widget build(BuildContext context) => AllowMultipleRawGestureDetector(
onTap: onTap,
child: Icon(
OptimusIcons.cross_close,
Expand All @@ -431,26 +431,3 @@ class _ClearAllButton extends StatelessWidget {
),
);
}

class _CustomRawGestureDetector extends RawGestureDetector {
_CustomRawGestureDetector({
GestureTapCallback? onTap,
super.child,
}) : super(
behavior: HitTestBehavior.opaque,
gestures: <Type, GestureRecognizerFactory>{
_AllowMultipleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
_AllowMultipleGestureRecognizer>(
_AllowMultipleGestureRecognizer.new,
(_AllowMultipleGestureRecognizer instance) =>
instance.onTap = onTap,
),
},
);
}

class _AllowMultipleGestureRecognizer extends TapGestureRecognizer {
@override
void rejectGesture(int pointer) => acceptGesture(pointer);
}

0 comments on commit 57a9881

Please sign in to comment.