-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement contextual menu on secondary click (#9)
* Switch from actions buttons to action menu * Rename action and submit on enter * Dart fixes * Refactor rename and delete dialogs * Convert mixin to extension * Add auto focus to buttons in dialogs * Change primary dialog button to FIlledButton * Improve keyboard accessibility for context menu * Improve keyboard navigation in list * Update * Fixups * Make new file dialog button filled * Remove unused code * Update dependencies * Fix compile issue for now. Awaiting PR * Use flutter master * Update libraries and pigeon
- Loading branch information
1 parent
69abff8
commit d59f067
Showing
19 changed files
with
406 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
class AdaptiveContextualMenu extends StatelessWidget { | ||
const AdaptiveContextualMenu({ | ||
super.key, | ||
required this.child, | ||
required this.menuChildren, | ||
this.focusNode, | ||
this.menuController, | ||
}); | ||
|
||
final Widget child; | ||
final List<Widget> menuChildren; | ||
|
||
final FocusNode? focusNode; | ||
final MenuController? menuController; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Focus( | ||
canRequestFocus: false, | ||
onKeyEvent: _onKeyEvent, | ||
child: GestureDetector( | ||
onTapDown: _handleTapDown, | ||
onSecondaryTapDown: _handleSecondaryTapDown, | ||
child: MenuAnchor( | ||
consumeOutsideTap: false, | ||
controller: menuController, | ||
menuChildren: menuChildren, | ||
childFocusNode: focusNode, | ||
child: child, | ||
), | ||
), | ||
); | ||
} | ||
|
||
void _handleSecondaryTapDown(TapDownDetails details) { | ||
menuController?.open(position: details.localPosition); | ||
} | ||
|
||
void _handleTapDown(TapDownDetails details) { | ||
switch (defaultTargetPlatform) { | ||
case TargetPlatform.android: | ||
case TargetPlatform.fuchsia: | ||
case TargetPlatform.linux: | ||
case TargetPlatform.windows: | ||
// Don't open the menu on these platforms with a Ctrl-tap (or a | ||
// tap). | ||
break; | ||
case TargetPlatform.iOS: | ||
case TargetPlatform.macOS: | ||
// Only open the menu on these platforms if the control button is down | ||
// when the tap occurs. | ||
if (HardwareKeyboard.instance.logicalKeysPressed | ||
.contains(LogicalKeyboardKey.controlLeft) || | ||
HardwareKeyboard.instance.logicalKeysPressed | ||
.contains(LogicalKeyboardKey.controlRight)) { | ||
menuController?.open(position: details.localPosition); | ||
} | ||
} | ||
} | ||
|
||
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) { | ||
if (node.hasFocus) { | ||
final isCtrl = HardwareKeyboard.instance.logicalKeysPressed | ||
.contains(LogicalKeyboardKey.controlLeft) || HardwareKeyboard.instance.logicalKeysPressed | ||
.contains(LogicalKeyboardKey.controlRight); | ||
if (event.logicalKey == LogicalKeyboardKey.enter && isCtrl) { | ||
menuController?.open(); | ||
} | ||
} | ||
|
||
return KeyEventResult.ignored; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.