feat: Implement menu open/close functionality in HomeScreen for improved user interaction

This commit is contained in:
2026-05-19 20:24:03 +02:00
parent 4912316845
commit 6035e3bc18
+54 -8
View File
@@ -50,6 +50,26 @@ class _HomeScreenState extends State<HomeScreen> {
bool _showDeletedNotes = false; bool _showDeletedNotes = false;
PointerDeviceKind _lastPointerKind = PointerDeviceKind.mouse; PointerDeviceKind _lastPointerKind = PointerDeviceKind.mouse;
void _openMenu() {
if (_isMenuOpen) {
return;
}
setState(() {
_isMenuOpen = true;
});
}
void _closeMenu() {
if (!_isMenuOpen) {
return;
}
setState(() {
_isMenuOpen = false;
});
}
bool _requiresLongPressToDrag(PointerDeviceKind kind) { bool _requiresLongPressToDrag(PointerDeviceKind kind) {
return kind == PointerDeviceKind.touch || return kind == PointerDeviceKind.touch ||
kind == PointerDeviceKind.stylus || kind == PointerDeviceKind.stylus ||
@@ -172,9 +192,7 @@ class _HomeScreenState extends State<HomeScreen> {
} }
Future<void> _handleMenuItemTapped(String item) async { Future<void> _handleMenuItemTapped(String item) async {
setState(() { _closeMenu();
_isMenuOpen = false;
});
if (item == 'settings') { if (item == 'settings') {
widget.onOpenSettings(); widget.onOpenSettings();
@@ -546,6 +564,16 @@ class _HomeScreenState extends State<HomeScreen> {
}, },
), ),
Expanded( Expanded(
child: Listener(
onPointerDown: (PointerDownEvent event) {
if (_lastPointerKind == event.kind) {
return;
}
setState(() {
_lastPointerKind = event.kind;
});
},
child: Stack( child: Stack(
children: [ children: [
Padding( Padding(
@@ -555,6 +583,27 @@ class _HomeScreenState extends State<HomeScreen> {
), ),
child: body, child: body,
), ),
Positioned(
left: 0,
top: 0,
bottom: 0,
width: 28,
child: IgnorePointer(
ignoring:
_isMenuOpen ||
!_requiresLongPressToDrag(_lastPointerKind),
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onHorizontalDragUpdate:
(DragUpdateDetails details) {
if ((details.primaryDelta ?? 0) > 6) {
_openMenu();
}
},
child: const SizedBox.expand(),
),
),
),
Positioned.fill( Positioned.fill(
child: IgnorePointer( child: IgnorePointer(
ignoring: !_isMenuOpen, ignoring: !_isMenuOpen,
@@ -564,11 +613,7 @@ class _HomeScreenState extends State<HomeScreen> {
curve: Curves.easeOutCubic, curve: Curves.easeOutCubic,
child: GestureDetector( child: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: _closeMenu,
setState(() {
_isMenuOpen = false;
});
},
child: Container(color: Colors.black), child: Container(color: Colors.black),
), ),
), ),
@@ -595,6 +640,7 @@ class _HomeScreenState extends State<HomeScreen> {
], ],
), ),
), ),
),
], ],
), ),
), ),