Skip to content

Commit

Permalink
secondaryTap support for overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
juancastillo0 committed Jul 26, 2021
1 parent ea8163d commit 9cd4d10
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
42 changes: 34 additions & 8 deletions lib/widgets/portal/custom_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:snippet_generator/globals/option.dart';
import 'package:snippet_generator/widgets/globals.dart';
import 'package:snippet_generator/widgets/portal/global_stack.dart';
import 'package:snippet_generator/widgets/portal/portal_utils.dart';

enum OverlayGesture {
tap,
secondaryTap,
}

class CustomOverlayButton extends HookWidget {
final Widget Function(PortalNotifier) portalBuilder;
final Widget child;
final PortalBundler? builder;
final PortalParams params;
final OverlayGesture gesture;

const CustomOverlayButton({
required this.portalBuilder,
required this.child,
this.params = const PortalParams(),
this.builder,
this.gesture = OverlayGesture.tap,
Key? key,
}) : super(key: key);

const CustomOverlayButton.stack({
required this.portalBuilder,
required this.child,
this.params = const PortalParams(),
this.gesture = OverlayGesture.tap,
Key? key,
}) : builder = StackPortal.make,
super(key: key);

@override
Widget build(BuildContext context) {
final show = useState(false);
Expand All @@ -33,6 +50,21 @@ class CustomOverlayButton extends HookWidget {
final _childKey = useMemoized(() => GlobalKey());
final toggle = _portalNotifier.toggle;

final Widget _inner;
switch (gesture) {
case OverlayGesture.tap:
_inner = TextButton(
onPressed: toggle,
child: child,
);
break;
case OverlayGesture.secondaryTap:
_inner = GestureDetector(
onSecondaryTap: toggle,
child: child,
);
}

if (builder != null) {
return builder!(
show: show.value,
Expand All @@ -52,10 +84,7 @@ class CustomOverlayButton extends HookWidget {
),
child: KeyedSubtree(
key: _childKey,
child: TextButton(
onPressed: toggle,
child: child,
),
child: _inner,
),
);
}
Expand All @@ -64,10 +93,7 @@ class CustomOverlayButton extends HookWidget {
show: show.value,
portal: portalBuilder(_portalNotifier),
onTapOutside: toggle,
child: TextButton(
onPressed: toggle,
child: child,
),
child: _inner,
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/small_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ class SmallIconButton extends StatelessWidget {
final bool center;
final void Function()? onPressed;
final Widget child;
final double? splashRadius;

const SmallIconButton({
Key? key,
this.center = true,
required this.child,
required this.onPressed,
this.splashRadius,
}) : super(key: key);

@override
Expand All @@ -19,7 +21,7 @@ class SmallIconButton extends StatelessWidget {
constraints: const BoxConstraints(),
alignment: Alignment.center,
padding: EdgeInsets.zero,
splashRadius: 22,
splashRadius: splashRadius ?? 22,
iconSize: 18,
onPressed: onPressed,
);
Expand Down

0 comments on commit 9cd4d10

Please sign in to comment.