Skip to content

Instantly share code, notes, and snippets.

@icnahom
Created May 23, 2024 11:10
Show Gist options
  • Save icnahom/8a5ae7f568feb1475f036926a345a341 to your computer and use it in GitHub Desktop.
Save icnahom/8a5ae7f568feb1475f036926a345a341 to your computer and use it in GitHub Desktop.
GestureDetector's onDoubledTap Delay
import 'package:flutter/material.dart';
void main() => runApp(const MenuAnchorApp());
class MenuAnchorApp extends StatelessWidget {
const MenuAnchorApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const MenuAnchorExample(),
);
}
}
class MenuAnchorExample extends StatelessWidget {
const MenuAnchorExample({super.key});
@override
Widget build(BuildContext context) {
final menuAnchor = MenuAnchor(
builder: (BuildContext context, MenuController controller, Widget? child) {
return IconButton(
onPressed: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
icon: const Icon(Icons.more_horiz),
);
},
menuChildren: List<MenuItemButton>.generate(
3,
(int index) => MenuItemButton(
onPressed: () {},
child: Text('Item ${index + 1}'),
),
),
);
return Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {},
onDoubleTap: () {},
child: Container(
color: Colors.red,
height: 100,
width: 100,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Slow'),
menuAnchor,
],
),
),
),
GestureDetector(
onTap: () {},
child: Container(
color: Colors.blue,
height: 100,
width: 100,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Fast'),
menuAnchor,
],
),
),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment