Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Fix Request approval submenu interactions (#16851)

21pages31041137a5c3
diff --git a/flutter/lib/common/widgets/peer_card.dart b/flutter/lib/common/widgets/peer_card.dart
index 4a15e3837..40fd460b6 100644
--- a/flutter/lib/common/widgets/peer_card.dart
+++ b/flutter/lib/common/widgets/peer_card.dart
@@ -15,7 +15,6 @@ import '../../models/peer_model.dart';
import '../../models/platform_model.dart';
import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
import '../../desktop/widgets/popup_menu.dart';
-import 'request_approval_menu.dart';
import 'dart:math' as math;
typedef PopupMenuEntryBuilder = Future<List<mod_menu.PopupMenuEntry<String>>>
@@ -658,8 +657,10 @@ abstract class BasePeerCard extends StatelessWidget {
loginMethod: 'request-approval',
);
- return RequestApprovalMenu(
- title: translate('Request approval'),
+ return MenuEntrySubMenu<String>(
+ text: translate('Request approval'),
+ dismissParentOnCanceled: true,
+ arrowScale: 1.0,
padding: menuPadding,
entries: [
action('Connect'),
diff --git a/flutter/lib/common/widgets/request_approval_menu.dart b/flutter/lib/common/widgets/request_approval_menu.dart
deleted file mode 100644
index 2b6ee8bad..000000000
--- a/flutter/lib/common/widgets/request_approval_menu.dart
+++ /dev/null
@@ -1,52 +0,0 @@
-import 'package:flutter/material.dart';
-
-import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
-import '../../desktop/widgets/popup_menu.dart';
-
-class RequestApprovalMenu extends MenuEntryBase<String> {
- final String title;
- final List<MenuEntryButton<String>> entries;
- final EdgeInsets? padding;
- final double arrowScale;
-
- RequestApprovalMenu(
- {required this.title,
- required this.entries,
- this.padding,
- this.arrowScale = 1.0});
-
- @override
- List<mod_menu.PopupMenuEntry<String>> build(
- BuildContext context, MenuConfig conf) {
- final theme = Theme.of(context);
- final checkboxTheme = CheckboxTheme.of(context);
- final checkboxWidth =
- ((checkboxTheme.materialTapTargetSize ?? theme.materialTapTargetSize) ==
- MaterialTapTargetSize.padded
- ? kMinInteractiveDimension
- : kMinInteractiveDimension - 8) +
- (checkboxTheme.visualDensity ?? theme.visualDensity)
- .baseSizeAdjustment
- .dx;
- final arrowInset = (checkboxWidth - (IconTheme.of(context).size ?? 24)) / 2;
- return MenuEntrySubMenu<String>(
- text: title,
- dismissParentOnCanceled: true,
- arrowScale: arrowScale,
- padding: (padding ?? EdgeInsets.zero)
- .copyWith(right: (padding?.right ?? 0) + arrowInset),
- entries: entries
- .map((entry) => MenuEntryButton<String>(
- childBuilder: entry.childBuilder,
- proc: entry.proc,
- padding: entry.padding,
- enabled: entry.enabled,
- dismissOnClicked: true,
- dismissCallback: () {
- if (Navigator.canPop(context)) Navigator.pop(context);
- },
- ))
- .toList(),
- ).build(context, conf);
- }
-}
diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart
index f484697ca..e552a772d 100644
--- a/flutter/lib/desktop/pages/connection_page.dart
+++ b/flutter/lib/desktop/pages/connection_page.dart
@@ -18,7 +18,6 @@ import '../../common.dart';
import '../../common/formatter/id_formatter.dart';
import '../../common/widgets/peer_tab_page.dart';
import '../../common/widgets/autocomplete.dart';
-import '../../common/widgets/request_approval_menu.dart';
import '../../models/platform_model.dart';
import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
@@ -341,7 +340,7 @@ class _ConnectionPageState extends State<ConnectionPage>
isTcpTunneling: isTcpTunneling);
}
- RequestApprovalMenu _requestApprovalMenu(BuildContext context) {
+ MenuEntrySubMenu<String> _requestApprovalMenu(BuildContext context) {
MenuEntryButton<String> action(String title,
{bool isFileTransfer = false,
bool isViewCamera = false,
@@ -359,8 +358,9 @@ class _ConnectionPageState extends State<ConnectionPage>
dismissOnClicked: true,
);
- return RequestApprovalMenu(
- title: translate('Request approval'),
+ return MenuEntrySubMenu<String>(
+ text: translate('Request approval'),
+ dismissParentOnCanceled: true,
padding: EdgeInsets.symmetric(horizontal: kDesktopMenuPadding.left),
arrowScale: MenuConfig.iconScale,
entries: [
diff --git a/flutter/lib/desktop/widgets/material_mod_popup_menu.dart b/flutter/lib/desktop/widgets/material_mod_popup_menu.dart
index 19cd0d153..d739c4736 100644
--- a/flutter/lib/desktop/widgets/material_mod_popup_menu.dart
+++ b/flutter/lib/desktop/widgets/material_mod_popup_menu.dart
@@ -323,6 +323,9 @@ class PopupMenuItem<T> extends PopupMenuEntry<T> {
/// [PopupMenuItem]. The first, `T`, must match the type argument of that widget
/// class, and is the type of values returned from this menu.
class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
+ @protected
+ FocusNode? get focusNode => null;
+
/// The menu item contents.
///
/// Used by the [build] method.
@@ -388,8 +391,35 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
// child: item,
// ),
child: TextButton(
+ focusNode: focusNode,
onPressed: widget.enabled ? handleTap : null,
- child: item,
+ style: ButtonStyle(
+ shape: const MaterialStatePropertyAll(RoundedRectangleBorder()),
+ overlayColor: MaterialStateProperty.resolveWith((states) {
+ final color = theme.colorScheme.onSurface;
+ if (states.contains(MaterialState.pressed)) {
+ return color.withOpacity(0.1);
+ }
+ if (states.contains(MaterialState.hovered)) {
+ return color.withOpacity(0.08);
+ }
+ if (states.contains(MaterialState.focused)) {
+ return color.withOpacity(0.1);
+ }
+ return Colors.transparent;
+ }),
+ ),
+ child: TextButtonTheme(
+ data: TextButtonThemeData(
+ // Inner buttons keep their layout and callbacks; the row paints feedback.
+ style: (TextButtonTheme.of(context).style ?? const ButtonStyle())
+ .copyWith(
+ overlayColor: const MaterialStatePropertyAll(Colors.transparent),
+ splashFactory: NoSplash.splashFactory,
+ ),
+ ),
+ child: item,
+ ),
),
),
);
@@ -800,6 +830,62 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
}
}
+class PopupMenuOverlay<T> extends StatelessWidget {
+ const PopupMenuOverlay({
+ required this.anchor,
+ required this.items,
+ super.key,
+ });
+
+ final Rect anchor;
+ final List<PopupMenuEntry<T>> items;
+
+ @override
+ Widget build(BuildContext context) {
+ final mediaQuery = MediaQuery.of(context);
+ final theme = PopupMenuTheme.of(context);
+ return MediaQuery.removePadding(
+ context: context,
+ removeTop: true,
+ removeBottom: true,
+ removeLeft: true,
+ removeRight: true,
+ child: LayoutBuilder(builder: (context, constraints) {
+ return CustomSingleChildLayout(
+ delegate: _PopupMenuRouteLayout(
+ RelativeRect.fromRect(anchor.shift(Offset(anchor.width, 0)),
+ Offset.zero & constraints.biggest),
+ const [],
+ null,
+ Directionality.of(context),
+ mediaQuery.padding,
+ DisplayFeatureSubScreen.avoidBounds(mediaQuery).toSet(),
+ submenuAnchor: anchor,
+ ),
+ child: Material(
+ shape: theme.shape,
+ color: theme.color,
+ type: MaterialType.card,
+ elevation: theme.elevation ?? 8.0,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(
+ minWidth: _kMenuMinWidth, maxWidth: _kMenuMaxWidth),
+ child: IntrinsicWidth(
+ stepWidth: _kMenuWidthStep,
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.symmetric(
+ vertical: _kMenuVerticalPadding),
+ child: ListBody(children: items),
+ ),
+ ),
+ ),
+ ),
+ );
+ }),
+ );
+ }
+}
+
class _PopupMenuRoute<T> extends PopupRoute<T> {
_PopupMenuRoute({
required this.position,
diff --git a/flutter/lib/desktop/widgets/popup_menu.dart b/flutter/lib/desktop/widgets/popup_menu.dart
index c66f2b499..6a1bbdf9f 100644
--- a/flutter/lib/desktop/widgets/popup_menu.dart
+++ b/flutter/lib/desktop/widgets/popup_menu.dart
@@ -1,6 +1,8 @@
+import 'dart:async';
import 'dart:core';
import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart' show RenderListBody;
import 'package:get/get.dart';
import '../../common.dart';
@@ -283,7 +285,7 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
);
onPressed() {
if (opt.dismissOnClicked && Navigator.canPop(context)) {
- Navigator.pop(context);
+ if (!_SubmenuScope.dismiss(context)) Navigator.pop(context);
if (opt.dismissCallback != null) {
opt.dismissCallback!();
}
@@ -291,7 +293,7 @@ class MenuEntryRadios<T> extends MenuEntryBase<T> {
setOption(opt.value);
}
- return mod_menu.PopupMenuItem(
+ return _MenuEntryButtonItem<T>(
padding: EdgeInsets.zero,
height: conf.height,
child: Container(
@@ -355,7 +357,7 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
mod_menu.PopupMenuEntry<T> _buildSecondMenu(
BuildContext context, MenuConfig conf, MenuEntryRadioOption opt) {
- return mod_menu.PopupMenuItem(
+ return _MenuEntryButtonItem<T>(
padding: EdgeInsets.zero,
height: conf.height,
child: Container(
@@ -397,7 +399,7 @@ class MenuEntrySubRadios<T> extends MenuEntryBase<T> {
),
onPressed: () {
if (opt.dismissOnClicked && Navigator.canPop(context)) {
- Navigator.pop(context);
+ if (!_SubmenuScope.dismiss(context)) Navigator.pop(context);
if (opt.dismissCallback != null) {
opt.dismissCallback!();
}
@@ -476,7 +478,7 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
tryPop(BuildContext context) {
if (dismissOnClicked && Navigator.canPop(context)) {
- Navigator.pop(context);
+ if (!_SubmenuScope.dismiss(context)) Navigator.pop(context);
super.dismissCallback?.call();
}
}
@@ -490,7 +492,7 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
fontWeight: FontWeight.normal)
.obs;
return [
- mod_menu.PopupMenuItem(
+ _MenuEntryButtonItem<T>(
padding: EdgeInsets.zero,
height: conf.height,
child: Container(
@@ -687,18 +689,26 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
List<mod_menu.PopupMenuEntry<T>> build(
BuildContext context, MenuConfig conf) {
super.enabled ??= true.obs;
+ final theme = Theme.of(context);
+ final checkboxTheme = CheckboxTheme.of(context);
+ final checkboxWidth =
+ ((checkboxTheme.materialTapTargetSize ?? theme.materialTapTargetSize) ==
+ MaterialTapTargetSize.padded
+ ? kMinInteractiveDimension
+ : kMinInteractiveDimension - 8) +
+ (checkboxTheme.visualDensity ?? theme.visualDensity)
+ .baseSizeAdjustment
+ .dx;
+ final arrowInset = (checkboxWidth - (IconTheme.of(context).size ?? 24)) / 2;
return [
- PopupMenuChildrenItem(
- enabled: super.enabled,
+ _PopupSubMenuItem<T>(
+ enabled: super.enabled!,
height: conf.height,
- padding: padding,
+ padding: (padding ?? EdgeInsets.zero)
+ .copyWith(right: (padding?.right ?? 0) + arrowInset),
dismissParentOnCanceled: dismissParentOnCanceled,
- useButtonLayout: true,
- position: mod_menu.PopupMenuPosition.overSide,
- itemBuilder: (BuildContext context) => entries
- .map((entry) => entry.build(context, conf))
- .expand((i) => i)
- .toList(),
+ entries: entries,
+ config: conf,
child: Row(children: [
Obx(() => Text(
text,
@@ -725,6 +735,242 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
}
}
+class _PopupSubMenuItem<T> extends mod_menu.PopupMenuEntry<T> {
+ const _PopupSubMenuItem({
+ required this.height,
+ required this.padding,
+ required this.child,
+ required this.entries,
+ required this.config,
+ required this.enabled,
+ required this.dismissParentOnCanceled,
+ });
+
+ @override
+ final double height;
+ final EdgeInsets padding;
+ final Widget child;
+ final RxBool enabled;
+ final bool dismissParentOnCanceled;
+ final List<MenuEntryBase<T>> entries;
+ final MenuConfig config;
+
+ @override
+ bool represents(T? value) => false;
+
+ @override
+ State<_PopupSubMenuItem<T>> createState() => _PopupSubMenuItemState<T>();
+}
+
+class _PopupSubMenuItemState<T> extends State<_PopupSubMenuItem<T>> {
+ Timer? _hoverTimer;
+ final _submenuController = OverlayPortalController();
+ bool get _submenuOpen => _submenuController.isShowing;
+
+ @override
+ void dispose() {
+ _hoverTimer?.cancel();
+ super.dispose();
+ }
+
+ void _hoverTrigger(bool hovered) {
+ if (_submenuOpen || !widget.enabled.value) return;
+ _hoverTimer?.cancel();
+ if (hovered) {
+ _hoverTimer = Timer(const Duration(milliseconds: 200), _openSubmenu);
+ }
+ }
+
+ void _openSubmenu() {
+ _hoverTimer?.cancel();
+ if (!mounted ||
+ !widget.enabled.value ||
+ widget.entries.isEmpty ||
+ _submenuOpen ||
+ ModalRoute.of(context)?.isCurrent != true) {
+ return;
+ }
+ setState(_submenuController.show);
+ }
+
+ void _closeSubmenu() {
+ _hoverTimer?.cancel();
+ if (mounted && _submenuOpen) setState(_submenuController.hide);
+ }
+
+ void _dismissSubmenu() {
+ _closeSubmenu();
+ if (widget.dismissParentOnCanceled &&
+ ModalRoute.of(context)?.isCurrent == true) {
+ Navigator.pop(context);
+ }
+ }
+
+ Widget _buildSubmenu(BuildContext overlayContext) {
+ final button = context.findRenderObject();
+ final overlay = Overlay.of(context).context.findRenderObject();
+ if (button is! RenderBox || overlay is! RenderBox) {
+ return const SizedBox.shrink();
+ }
+ final anchor =
+ button.localToGlobal(Offset.zero, ancestor: overlay) & button.size;
+ final parentMenu = Scrollable.maybeOf(context)?.context.findRenderObject();
+ final parentItems =
+ context.findAncestorRenderObjectOfType<RenderListBody>();
+ final parentBounds = parentMenu is RenderBox && parentItems != null
+ ? (parentMenu.localToGlobal(Offset.zero, ancestor: overlay) &
+ parentMenu.size)
+ .intersect(
+ parentItems.localToGlobal(Offset.zero, ancestor: overlay) &
+ parentItems.size)
+ : Rect.zero;
+ return Stack(children: [
+ Positioned.fill(
+ child: MouseRegion(
+ opaque: false,
+ hitTestBehavior: HitTestBehavior.translucent,
+ onExit: (_) => _hoverTimer?.cancel(),
+ onHover: (event) {
+ final position = overlay.globalToLocal(event.position);
+ if (parentBounds.contains(position) && !anchor.contains(position)) {
+ // Allow crossing parent rows on the way to the submenu.
+ if (_hoverTimer?.isActive != true) {
+ _hoverTimer =
+ Timer(const Duration(milliseconds: 400), _closeSubmenu);
+ }
+ } else {
+ _hoverTimer?.cancel();
+ }
+ },
+ child: Listener(
+ behavior: HitTestBehavior.translucent,
+ onPointerDown: (event) {
+ final position = overlay.globalToLocal(event.position);
+ if (parentBounds.contains(position) && !anchor.contains(position)) {
+ _closeSubmenu();
+ }
+ },
+ child: const SizedBox.expand(),
+ ),
+ )),
+ if (!widget.dismissParentOnCanceled)
+ Positioned.fill(
+ child: ClipPath(
+ clipper: _OutsideParentMenuClipper(parentBounds),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _closeSubmenu,
+ ),
+ )),
+ _SubmenuScope(
+ onDismiss: _dismissSubmenu,
+ child: Actions(
+ actions: {
+ DismissIntent: CallbackAction<DismissIntent>(onInvoke: (_) {
+ _dismissSubmenu();
+ return null;
+ }),
+ },
+ child: FocusScope(
+ // Autofocus inside the new scope so the focused trigger cannot block it.
+ child: Focus(
+ autofocus: true,
+ skipTraversal: true,
+ child: Builder(
+ builder: (context) => mod_menu.PopupMenuOverlay<T>(
+ anchor: anchor,
+ items: widget.entries
+ .expand(
+ (entry) => entry.build(context, widget.config))
+ .toList(),
+ )),
+ ),
+ ),
+ ),
+ ),
+ ]);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final highlight = Theme.of(context).colorScheme.onSurface.withOpacity(0.08);
+ final trigger = Obx(() => MouseRegion(
+ onEnter: (_) => _hoverTrigger(true),
+ onExit: (_) => _hoverTrigger(false),
+ child: TextButton(
+ onPressed: widget.enabled.value ? _openSubmenu : null,
+ style: ButtonStyle(
+ shape: const MaterialStatePropertyAll(RoundedRectangleBorder()),
+ backgroundColor: MaterialStateProperty.resolveWith((states) =>
+ !states.contains(MaterialState.disabled) &&
+ (_submenuOpen ||
+ states.contains(MaterialState.hovered) ||
+ states.contains(MaterialState.focused) ||
+ states.contains(MaterialState.pressed))
+ ? highlight
+ : Colors.transparent),
+ overlayColor: const MaterialStatePropertyAll(Colors.transparent),
+ ),
+ // Retain the old spacing, with one focus stop and one hover highlight.
+ child: ExcludeFocus(
+ child: TextButton(
+ onPressed: widget.enabled.value ? _openSubmenu : null,
+ style: const ButtonStyle(
+ overlayColor: MaterialStatePropertyAll(Colors.transparent),
+ splashFactory: NoSplash.splashFactory,
+ ),
+ child: Container(
+ alignment: AlignmentDirectional.centerStart,
+ height: widget.height,
+ padding: widget.padding,
+ child: widget.child,
+ ),
+ ),
+ ),
+ ),
+ ));
+ return OverlayPortal(
+ controller: _submenuController,
+ overlayChildBuilder: _buildSubmenu,
+ child: trigger,
+ );
+ }
+}
+
+class _SubmenuScope extends InheritedWidget {
+ const _SubmenuScope({required this.onDismiss, required super.child});
+
+ final VoidCallback onDismiss;
+
+ static bool dismiss(BuildContext context) {
+ final scope = context.getInheritedWidgetOfExactType<_SubmenuScope>();
+ if (scope == null || ModalRoute.of(context)?.isCurrent != true) {
+ return false;
+ }
+ scope.onDismiss();
+ return true;
+ }
+
+ @override
+ bool updateShouldNotify(_SubmenuScope oldWidget) => false;
+}
+
+class _OutsideParentMenuClipper extends CustomClipper<Path> {
+ const _OutsideParentMenuClipper(this.parentBounds);
+
+ final Rect parentBounds;
+
+ @override
+ Path getClip(Size size) => Path()
+ ..fillType = PathFillType.evenOdd
+ ..addRect(Offset.zero & size)
+ ..addRect(parentBounds);
+
+ @override
+ bool shouldReclip(_OutsideParentMenuClipper oldClipper) =>
+ parentBounds != oldClipper.parentBounds;
+}
+
class MenuEntryButton<T> extends MenuEntryBase<T> {
final Widget Function(TextStyle? style) childBuilder;
Function() proc;
@@ -751,7 +997,7 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
onPressed: super.enabled!.value
? () {
if (super.dismissOnClicked && Navigator.canPop(context)) {
- Navigator.pop(context);
+ if (!_SubmenuScope.dismiss(context)) Navigator.pop(context);
if (super.dismissCallback != null) {
super.dismissCallback!();
}
@@ -774,7 +1020,7 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
List<mod_menu.PopupMenuEntry<T>> build(
BuildContext context, MenuConfig conf) {
return [
- mod_menu.PopupMenuItem(
+ _MenuEntryButtonItem<T>(
padding: EdgeInsets.zero,
height: conf.height,
child: _buildChild(context, conf),
@@ -783,6 +1029,31 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
}
}
+class _MenuEntryButtonItem<T> extends mod_menu.PopupMenuItem<T> {
+ const _MenuEntryButtonItem({super.padding, super.height, required super.child});
+
+ @override
+ _MenuEntryButtonItemState<T> createState() => _MenuEntryButtonItemState<T>();
+}
+
+class _MenuEntryButtonItemState<T>
+ extends mod_menu.PopupMenuItemState<T, _MenuEntryButtonItem<T>> {
+ // The inner button already handles keyboard activation.
+ @override
+ final FocusNode focusNode = FocusNode(skipTraversal: true);
+
+ @override
+ void handleTap() {
+ if (!_SubmenuScope.dismiss(context)) super.handleTap();
+ }
+
+ @override
+ void dispose() {
+ focusNode.dispose();
+ super.dispose();
+ }
+}
+
class CustomPopupMenuTheme {
static const Color commonColor = MyTheme.accent;
// kMinInteractiveDimension
diff --git a/flutter/test/popup_menu_hover_test.dart b/flutter/test/popup_menu_hover_test.dart
new file mode 100644
index 000000000..ed2d2e25e
--- /dev/null
+++ b/flutter/test/popup_menu_hover_test.dart
@@ -0,0 +1,318 @@
+import 'package:flutter/gestures.dart' show PointerDeviceKind;
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_hbb/common.dart' show MyTheme;
+import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
+
+import 'request_approval_menu_test.dart' as menu;
+
+void main() {
+ testWidgets('submenu highlight stays steady while opening', (tester) async {
+ for (final theme in [MyTheme.lightTheme, MyTheme.darkTheme]) {
+ await menu.openMenu(tester, [], theme: theme);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: Offset.zero);
+ await mouse.moveTo(tester.getCenter(menu.approvalRow));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 199));
+ for (final milliseconds in [1, 16, 50]) {
+ await tester.pump(Duration(milliseconds: milliseconds));
+ final background = tester.widget<PhysicalShape>(find.descendant(
+ of: menu.approvalRow, matching: find.byType(PhysicalShape)).first);
+ expect(background.color, theme.colorScheme.onSurface.withOpacity(0.08));
+ final innerButton = find.ancestor(
+ of: find.text('Request approval'),
+ matching: find.byType(TextButton)).first;
+ final ink = Material.of(tester.element(innerButton)) as RenderObject;
+ expect(ink, isNot(paints..rect(color: Colors.black.withOpacity(0.08))));
+ }
+ expect(find.text('Terminal'), findsOneWidget);
+ await tester.tapAt(const Offset(2, 2));
+ await tester.pumpAndSettle();
+ await mouse.removePointer();
+ }
+ });
+
+ testWidgets('menu hover paints one full row and keeps its action',
+ (tester) async {
+ for (final theme in [MyTheme.lightTheme, MyTheme.darkTheme]) {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, theme: theme);
+ final text = find.text('Connect');
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: Offset.zero);
+ await mouse.moveTo(tester.getCenter(text));
+ await tester.pumpAndSettle();
+ final innerButton =
+ find.ancestor(of: text, matching: find.byType(TextButton)).first;
+ final rowInk = Material.of(tester.element(innerButton)) as RenderObject;
+ expect(rowInk,
+ paints..rect(color: theme.colorScheme.onSurface.withOpacity(0.08)));
+ final innerInk = Material.of(tester.element(text)) as RenderObject;
+ expect(innerInk, paints..rect(color: Colors.transparent));
+ await tester.tap(text);
+ await tester.pumpAndSettle();
+ expect(actions, ['Connect']);
+ expect(find.text('Request approval'), findsNothing);
+ await mouse.removePointer();
+ }
+ });
+
+ testWidgets('menu actions have one Tab stop and RDP edit stays independent',
+ (tester) async {
+ for (final theme in [MyTheme.lightTheme, MyTheme.darkTheme]) {
+ for (final action in ['Rename', 'RDP', 'Edit RDP']) {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, theme: theme);
+ final text = find.text(action == 'Edit RDP' ? 'RDP' : action);
+ final button =
+ find.ancestor(of: text, matching: find.byType(TextButton)).first;
+ final outerFocus = Focus.of(tester.element(button));
+ for (var i = 0; i < 30 && !outerFocus.hasFocus; i++) {
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.pump();
+ }
+ expect(Focus.of(tester.element(text)).hasPrimaryFocus, isTrue);
+ await tester.pumpAndSettle();
+ final ink = Material.of(tester.element(button)) as RenderObject;
+ expect(ink,
+ paints..rect(color: theme.colorScheme.onSurface.withOpacity(0.1)));
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.pump();
+ if (action == 'Rename') {
+ expect(outerFocus.hasFocus, isFalse);
+ } else {
+ expect(Focus.of(tester.element(find.byIcon(Icons.edit))).hasPrimaryFocus,
+ isTrue);
+ }
+ if (action != 'Edit RDP') {
+ await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
+ await tester.pump();
+ }
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+ expect(actions, [action]);
+ expect(find.text('Request approval'), findsNothing);
+ }
+ }
+ });
+
+ testWidgets('parent actions remain clickable while the submenu is open',
+ (tester) async {
+ tester.view.physicalSize = const Size(1200, 1000);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ for (final delay in [Duration.zero, const Duration(milliseconds: 100)]) {
+ for (final action in ['Connect', 'Edit RDP', 'Keep session']) {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, extraEntries: [
+ MenuEntrySwitchSync<String>(
+ switchType: SwitchType.scheckbox,
+ text: 'Keep session',
+ currentValue: false,
+ setter: (value) async => actions.add('keep:$value'),
+ ),
+ ]);
+ await tester.tap(find.text('Request approval'));
+ await tester.pumpAndSettle();
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ final target = action == 'Edit RDP'
+ ? find.byIcon(Icons.edit)
+ : find.text(action).first;
+ final position = tester.getCenter(target);
+ await mouse.moveTo(position);
+ if (delay != Duration.zero) await tester.pump(delay);
+ await mouse.down(position);
+ await mouse.up();
+ await tester.pumpAndSettle();
+ expect(actions, [action == 'Keep session' ? 'keep:true' : action]);
+ expect(find.text('Terminal'), findsNothing);
+ expect(find.text('Request approval'),
+ action == 'Keep session' ? findsOneWidget : findsNothing);
+ if (action == 'Keep session') {
+ await tester.tap(find.text('Rename'));
+ await tester.pumpAndSettle();
+ }
+ await mouse.removePointer();
+ }
+ }
+ });
+
+ testWidgets('parent hover and dialog action work during the close delay',
+ (tester) async {
+ tester.view.physicalSize = const Size(1200, 1000);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, extraEntries: [
+ MenuEntryButton<String>(
+ childBuilder: (style) => Text('Open dialog', style: style),
+ dismissOnClicked: true,
+ proc: () {
+ actions.add('dialog');
+ showDialog<void>(
+ context: tester.element(find.text('Open menu')),
+ builder: (_) =>
+ const AlertDialog(content: Text('Dialog stays open')),
+ );
+ },
+ ),
+ ]);
+ await tester.tap(find.text('Request approval'));
+ await tester.pumpAndSettle();
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ addTearDown(mouse.removePointer);
+ final target = find.text('Open dialog');
+ await mouse.moveTo(tester.getCenter(target));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ final button =
+ find.ancestor(of: target, matching: find.byType(TextButton)).first;
+ final context = tester.element(button);
+ expect(
+ Material.of(context) as RenderObject,
+ paints
+ ..rect(
+ color:
+ Theme.of(context).colorScheme.onSurface.withOpacity(0.08)));
+ await tester.tap(target);
+ await tester.pump(const Duration(milliseconds: 600));
+ await tester.pumpAndSettle();
+ expect(actions, ['dialog']);
+ expect(find.text('Request approval'), findsNothing);
+ expect(find.text('Terminal'), findsNothing);
+ expect(find.text('Dialog stays open'), findsOneWidget);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pumpAndSettle();
+ expect(find.text('Open menu'), findsOneWidget);
+ });
+
+ testWidgets('Enter on the first switch row focus toggles the option',
+ (tester) async {
+ for (final switchType in SwitchType.values) {
+ for (final dismiss in [false, true]) {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, extraEntries: [
+ MenuEntrySwitchSync<String>(
+ switchType: switchType,
+ text: 'Keep session',
+ currentValue: false,
+ setter: (value) async => actions.add('keep:$value'),
+ dismissOnClicked: dismiss,
+ ),
+ ]);
+ final text = find.text('Keep session');
+ final button =
+ find.ancestor(of: text, matching: find.byType(TextButton)).first;
+ final rowFocus = Focus.of(tester.element(button));
+ for (var i = 0; i < 30 && !rowFocus.hasFocus; i++) {
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.pump();
+ }
+ expect(rowFocus.hasFocus, isTrue);
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+ expect(actions, ['keep:true']);
+ expect(text, dismiss ? findsNothing : findsOneWidget);
+ if (!dismiss) {
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.space);
+ await tester.pumpAndSettle();
+ expect(actions, ['keep:true', 'keep:false']);
+ expect(text, findsOneWidget);
+ await tester.tap(find.text('Rename'));
+ await tester.pumpAndSettle();
+ }
+ }
+ }
+ });
+
+ for (final submenu in [false, true]) {
+ final name = submenu ? 'radio submenu' : 'radio menu';
+ testWidgets('Enter on the first $name row focus selects the option',
+ (tester) async {
+ var selected = 'one';
+ final changes = <String>[];
+ List<MenuEntryRadioOption> options() => [
+ MenuEntryRadioOption(text: 'First option', value: 'one'),
+ MenuEntryRadioOption(text: 'Second option', value: 'two'),
+ ];
+ Future<String> current() async => selected;
+ Future<void> select(String oldValue, String value) async {
+ selected = value;
+ changes.add(value);
+ }
+
+ await menu.openMenu(tester, [], extraEntries: [
+ if (submenu)
+ MenuEntrySubRadios<String>(
+ text: 'Radio options',
+ optionsGetter: options,
+ curOptionGetter: current,
+ optionSetter: select,
+ )
+ else
+ MenuEntryRadios<String>(
+ text: 'Radio options',
+ optionsGetter: options,
+ curOptionGetter: current,
+ optionSetter: select,
+ ),
+ ]);
+ if (submenu) {
+ await tester.tap(find.text('Radio options'));
+ await tester.pumpAndSettle();
+ }
+ final text = find.text('Second option');
+ final buttons = find.ancestor(of: text, matching: find.byType(TextButton));
+ final rowFocus = Focus.of(tester.element(buttons.first));
+ for (var i = 0; i < 30 && !rowFocus.hasFocus; i++) {
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.pump();
+ }
+ expect(rowFocus.hasFocus, isTrue);
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+ expect(changes, ['two']);
+ expect(find.descendant(of: buttons.last, matching: find.byIcon(Icons.check)),
+ findsOneWidget);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pumpAndSettle();
+ if (submenu) {
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pumpAndSettle();
+ }
+ });
+ }
+
+ testWidgets('checkbox and row toggle once without closing the menu',
+ (tester) async {
+ for (final checkbox in [false, true]) {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, extraEntries: [
+ MenuEntrySwitchSync<String>(
+ switchType: SwitchType.scheckbox,
+ text: 'Keep session',
+ currentValue: false,
+ setter: (value) async => actions.add('keep:$value'),
+ ),
+ ]);
+ await tester
+ .tap(checkbox ? find.byType(Checkbox) : find.text('Keep session'));
+ await tester.pumpAndSettle();
+ expect(actions, ['keep:true']);
+ expect(find.text('Keep session'), findsOneWidget);
+ expect(tester.widget<Checkbox>(find.byType(Checkbox)).value, isTrue);
+ await tester.tap(find.text('Rename'));
+ await tester.pumpAndSettle();
+ }
+ });
+}
diff --git a/flutter/test/popup_submenu_test.dart b/flutter/test/popup_submenu_test.dart
new file mode 100644
index 000000000..10e6cd676
--- /dev/null
+++ b/flutter/test/popup_submenu_test.dart
@@ -0,0 +1,92 @@
+import 'dart:ui' show PointerDeviceKind;
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
+import 'package:get/get.dart';
+
+import 'request_approval_menu_test.dart' as menu;
+
+void main() {
+ testWidgets('submenu preserves mixed entries and their close policies',
+ (tester) async {
+ final actions = <String>[];
+ await menu.openMenu(tester, actions, extraEntries: [
+ MenuEntrySubMenu<String>(text: 'Options', entries: [
+ MenuEntryButton<String>(
+ childBuilder: (_) => const Text('Inspect'),
+ proc: () => actions.add('inspect'),
+ ),
+ MenuEntryDivider<String>(),
+ MenuEntrySwitchSync<String>(
+ switchType: SwitchType.scheckbox,
+ text: 'Keep session',
+ currentValue: false,
+ setter: (value) async => actions.add('keep:$value'),
+ ),
+ MenuEntryButton<String>(
+ childBuilder: (_) => const Text('Apply'),
+ proc: () => actions.add('apply'),
+ dismissOnClicked: true,
+ dismissCallback: () => actions.add('dismissed'),
+ ),
+ ]),
+ ]);
+ await tester.tap(find.text('Options'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Inspect'));
+ await tester.pumpAndSettle();
+ expect(find.text('Keep session'), findsOneWidget);
+ await tester.tap(find.byType(Checkbox));
+ await tester.pumpAndSettle();
+ expect(tester.widget<Checkbox>(find.byType(Checkbox)).value, isTrue);
+ await tester.tap(find.text('Apply'));
+ await tester.pumpAndSettle();
+ expect(actions, ['inspect', 'keep:true', 'dismissed', 'apply']);
+ expect(find.text('Apply'), findsNothing);
+ expect(find.text('Options'), findsOneWidget);
+ await tester.tap(find.text('Options'));
+ await tester.pumpAndSettle();
+ await tester.tapAt(const Offset(2, 2));
+ await tester.pumpAndSettle();
+ expect(find.text('Apply'), findsNothing);
+ expect(find.text('Options'), findsOneWidget);
+ await tester.tap(find.text('Rename'));
+ await tester.pumpAndSettle();
+ });
+
+ testWidgets('disabled submenu cannot open and can close its parent on cancel',
+ (tester) async {
+ final enabled = false.obs;
+ await menu.openMenu(tester, [], extraEntries: [
+ MenuEntrySubMenu<String>(
+ text: 'Options',
+ enabled: enabled,
+ dismissParentOnCanceled: true,
+ entries: [
+ MenuEntryButton<String>(
+ childBuilder: (_) => const Text('Inspect'),
+ proc: () {},
+ ),
+ ],
+ ),
+ ]);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ addTearDown(mouse.removePointer);
+ await mouse.moveTo(tester.getCenter(find.text('Options')));
+ await tester.pump(const Duration(milliseconds: 300));
+ await tester.tap(find.text('Options'));
+ await tester.pumpAndSettle();
+ expect(find.text('Inspect'), findsNothing);
+ enabled.value = true;
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Options'));
+ await tester.pumpAndSettle();
+ expect(find.text('Inspect'), findsOneWidget);
+ await tester.tapAt(const Offset(2, 2));
+ await tester.pumpAndSettle();
+ expect(find.text('Options'), findsNothing);
+ expect(find.text('Inspect'), findsNothing);
+ });
+}
diff --git a/flutter/test/request_approval_menu_test.dart b/flutter/test/request_approval_menu_test.dart
index 50ee92c37..efb6b7050 100644
--- a/flutter/test/request_approval_menu_test.dart
+++ b/flutter/test/request_approval_menu_test.dart
@@ -1,7 +1,8 @@
+import 'dart:ui' show PointerDeviceKind;
+
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
-import 'package:flutter_hbb/common/widgets/request_approval_menu.dart';
import 'package:flutter_hbb/desktop/widgets/material_mod_popup_menu.dart'
as mod_menu;
import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
@@ -16,10 +17,17 @@ const connectionTypes = [
'RDP',
];
+Finder get approvalRow => find.ancestor(
+ of: find.text('Request approval'),
+ matching: find.byWidgetPredicate(
+ (widget) => widget is mod_menu.PopupMenuEntry<String>));
+
Future<void> openMenu(WidgetTester tester, List<String> actions,
{ThemeData? theme,
EdgeInsets? padding,
bool includeRelay = false,
+ bool includeRename = true,
+ List<MenuEntryBase<String>> extraEntries = const [],
RelativeRect position = const RelativeRect.fromLTRB(20, 20, 780, 580)}) async {
MenuEntryButton<String> entry(String title, {bool requestApproval = false}) =>
MenuEntryButton<String>(
@@ -58,8 +66,10 @@ Future<void> openMenu(WidgetTester tester, List<String> actions,
padding: padding,
dismissOnClicked: true,
),
- RequestApprovalMenu(
- title: 'Request approval',
+ MenuEntrySubMenu<String>(
+ text: 'Request approval',
+ arrowScale: 1.0,
+ dismissParentOnCanceled: true,
padding: padding,
entries: [
for (final title in connectionTypes)
@@ -75,7 +85,8 @@ Future<void> openMenu(WidgetTester tester, List<String> actions,
padding: padding,
dismissOnClicked: true,
),
- entry('Rename'),
+ if (includeRename) entry('Rename'),
+ ...extraEntries,
]
.expand((entry) => entry.build(context,
const MenuConfig(commonColor: Colors.black, height: 20)))
@@ -92,6 +103,121 @@ Future<void> openMenu(WidgetTester tester, List<String> actions,
}
void main() {
+ testWidgets('last approval item stays open on click and when exiting below it',
+ (tester) async {
+ tester.view.physicalSize = const Size(1200, 800);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ final actions = <String>[];
+ await openMenu(tester, actions, includeRename: false);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ addTearDown(mouse.removePointer);
+ final trigger = tester.getCenter(approvalRow);
+ await mouse.moveTo(trigger);
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(find.text('Terminal'), findsNothing);
+ await mouse.moveTo(const Offset(2, 2));
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(find.text('Terminal'), findsNothing);
+
+ await mouse.moveTo(trigger);
+ await tester.pump(const Duration(milliseconds: 200));
+ await tester.pumpAndSettle();
+ expect(find.text('Terminal'), findsOneWidget);
+ for (final kind in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
+ if (kind == PointerDeviceKind.mouse) {
+ await mouse.down(trigger);
+ await mouse.up();
+ } else {
+ await tester.tapAt(trigger, kind: kind);
+ }
+ await tester.pumpAndSettle();
+ expect(find.text('Terminal'), findsOneWidget, reason: '$kind click');
+ expect(actions, isEmpty);
+ }
+ final bottom = tester.getRect(approvalRow).bottom;
+ for (final distance in [1.0, 20.0]) {
+ await mouse.moveTo(Offset(trigger.dx, bottom + distance));
+ await tester.pumpAndSettle();
+ expect(find.text('Terminal'), findsOneWidget);
+ }
+ final highlight = Theme.of(tester.element(approvalRow))
+ .colorScheme
+ .onSurface
+ .withOpacity(0.08);
+ expect(
+ tester
+ .widgetList<Material>(find.descendant(
+ of: approvalRow, matching: find.byType(Material)))
+ .where((material) => material.color == highlight),
+ hasLength(1));
+ await tester.pump(const Duration(seconds: 2));
+ expect(find.text('Show menu'), findsNothing);
+ await tester.tapAt(const Offset(2, 2));
+ await tester.pumpAndSettle();
+ });
+
+ testWidgets('approval delays closing over parent items and cancels on leaving',
+ (tester) async {
+ tester.view.physicalSize = const Size(1200, 800);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.resetPhysicalSize);
+ addTearDown(tester.view.resetDevicePixelRatio);
+ final actions = <String>[];
+ await openMenu(tester, actions);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ addTearDown(mouse.removePointer);
+ final trigger = tester.getCenter(approvalRow);
+ await mouse.moveTo(trigger);
+ await tester.pump(const Duration(milliseconds: 200));
+ await tester.pumpAndSettle();
+ await mouse.moveTo(tester.getCenter(find.text('Connect').last));
+ await tester.pump(const Duration(milliseconds: 400));
+ expect(find.text('Terminal'), findsOneWidget);
+ await mouse.moveTo(trigger);
+ await tester.pump(const Duration(milliseconds: 400));
+ expect(find.text('Terminal'), findsOneWidget);
+
+ await mouse.moveTo(tester.getCenter(find.text('Connect').last));
+ await mouse.moveTo(const Offset(2, 2));
+ await tester.pump(const Duration(seconds: 1));
+ await tester.pumpAndSettle();
+ expect(find.text('Terminal'), findsOneWidget);
+ expect(find.text('Request approval'), findsOneWidget);
+ expect(actions, isEmpty);
+ for (final destination in [
+ tester.getCenter(find.text('Terminal')),
+ trigger,
+ const Offset(2, 2),
+ ]) {
+ await mouse.moveTo(tester.getCenter(find.text('Rename')));
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(find.text('Terminal'), findsOneWidget);
+ await mouse.moveTo(destination);
+ await tester.pump(const Duration(milliseconds: 500));
+ expect(find.text('Terminal'), findsOneWidget);
+ }
+ await mouse.moveTo(trigger);
+ await tester.pumpAndSettle();
+ final connect = tester.getCenter(find.text('Connect').first);
+ await mouse.moveTo(connect);
+ await tester.pump(const Duration(milliseconds: 399));
+ expect(find.text('Terminal'), findsOneWidget);
+ await mouse.moveTo(connect + const Offset(1, 0));
+ await tester.pump(const Duration(milliseconds: 1));
+ await tester.pumpAndSettle();
+ expect(find.text('Terminal'), findsNothing);
+ expect(find.text('Request approval'), findsOneWidget);
+ expect(actions, isEmpty);
+ await tester.tap(find.text('Connect'));
+ await tester.pumpAndSettle();
+ expect(actions, ['Connect']);
+ expect(find.text('Request approval'), findsNothing);
+ });
+
testWidgets('submenu prefers the left screen edge when neither side fits',
(tester) async {
tester.view.physicalSize = const Size(500, 800);
@@ -104,7 +230,8 @@ void main() {
await tester.pumpAndSettle();
final submenu = tester.getRect(find.ancestor(
of: find.text('Connect').last,
- matching: find.byType(mod_menu.PopupMenuItem<String>)));
+ matching: find.byWidgetPredicate(
+ (widget) => widget is mod_menu.PopupMenuItem<String>)));
expect(submenu.left, closeTo(0, 0.01));
expect(submenu.right, lessThanOrEqualTo(500));
await tester.tapAt(const Offset(2, 2));
@@ -121,12 +248,13 @@ void main() {
await openMenu(tester, [],
position: RelativeRect.fromLTRB(atRight ? 1180 : 20, 20,
atRight ? 20 : 1180, 780));
- final parent = tester.getRect(find.byType(PopupMenuChildrenItem<String>));
+ final parent = tester.getRect(approvalRow);
await tester.tap(find.text('Request approval'));
await tester.pumpAndSettle();
final submenu = tester.getRect(find.ancestor(
of: find.text('Connect').last,
- matching: find.byType(mod_menu.PopupMenuItem<String>)));
+ matching: find.byWidgetPredicate(
+ (widget) => widget is mod_menu.PopupMenuItem<String>)));
if (atRight) {
expect(submenu.right, lessThanOrEqualTo(parent.left));
} else {
@@ -139,9 +267,22 @@ void main() {
testWidgets('approval trigger has one Tab stop and opens with Enter',
(tester) async {
- await openMenu(tester, []);
- bool approvalHasFocus() => FocusManager.instance.primaryFocus?.context
- ?.findAncestorWidgetOfExactType<PopupMenuChildrenItem<String>>() != null;
+ final actions = <String>[];
+ await openMenu(tester, actions);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: const Offset(2, 2));
+ addTearDown(mouse.removePointer);
+ bool approvalHasFocus() {
+ var focused = false;
+ FocusManager.instance.primaryFocus?.context?.visitAncestorElements((e) {
+ if (e == tester.element(approvalRow)) {
+ focused = true;
+ return false;
+ }
+ return true;
+ });
+ return focused;
+ }
for (var i = 0; i < 30 && !approvalHasFocus(); i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
@@ -160,7 +301,22 @@ void main() {
expect(approvalHasFocus(), isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
+ await tester.pump(const Duration(milliseconds: 500));
+ await tester.pumpAndSettle();
expect(find.text('Terminal (Run as administrator)'), findsOneWidget);
+ await tester.sendKeyEvent(LogicalKeyboardKey.tab);
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+ expect(actions, ['Connect:request-approval']);
+ expect(find.text('Request approval'), findsNothing);
+ await tester.tap(find.text('Open menu'));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Request approval'));
+ await tester.pumpAndSettle();
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pumpAndSettle();
+ expect(actions, ['Connect:request-approval']);
+ expect(find.text('Request approval'), findsNothing);
});
testWidgets('tapping outside the approval submenu closes both menus',
@@ -280,7 +436,7 @@ void main() {
]) {
final actions = <String>[];
await openMenu(tester, actions);
- final row = tester.getRect(find.byType(PopupMenuChildrenItem<String>));
+ final row = tester.getRect(approvalRow);
await tester.tapAt(corner.withinRect(row.deflate(2)));
await tester.pumpAndSettle();
expect(actions, isEmpty);