mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 12:59:58 +08:00
Merge pull request #477 from ClementBeal/feat-open-menu-with-right-click
feat: open ItemCardMenu with a right click
This commit is contained in:
@ -172,6 +172,7 @@ const kPb15 = EdgeInsets.only(
|
|||||||
const kPb70 = EdgeInsets.only(
|
const kPb70 = EdgeInsets.only(
|
||||||
bottom: 70,
|
bottom: 70,
|
||||||
);
|
);
|
||||||
|
const kSizedBoxEmpty = SizedBox();
|
||||||
const kHSpacer2 = SizedBox(width: 2);
|
const kHSpacer2 = SizedBox(width: 2);
|
||||||
const kHSpacer4 = SizedBox(width: 4);
|
const kHSpacer4 = SizedBox(width: 4);
|
||||||
const kHSpacer5 = SizedBox(width: 5);
|
const kHSpacer5 = SizedBox(width: 5);
|
||||||
|
@ -193,6 +193,9 @@ class EnvironmentItem extends ConsumerWidget {
|
|||||||
ref.read(selectedEnvironmentIdStateProvider.notifier).state = id;
|
ref.read(selectedEnvironmentIdStateProvider.notifier).state = id;
|
||||||
kEnvScaffoldKey.currentState?.closeDrawer();
|
kEnvScaffoldKey.currentState?.closeDrawer();
|
||||||
},
|
},
|
||||||
|
onSecondaryTap: () {
|
||||||
|
ref.read(selectedEnvironmentIdStateProvider.notifier).state = id;
|
||||||
|
},
|
||||||
focusNode: ref.watch(nameTextFieldFocusNodeProvider),
|
focusNode: ref.watch(nameTextFieldFocusNodeProvider),
|
||||||
onChangedNameEditor: (value) {
|
onChangedNameEditor: (value) {
|
||||||
value = value.trim();
|
value = value.trim();
|
||||||
|
@ -223,6 +223,9 @@ class RequestItem extends ConsumerWidget {
|
|||||||
ref.read(selectedIdStateProvider.notifier).state = id;
|
ref.read(selectedIdStateProvider.notifier).state = id;
|
||||||
kHomeScaffoldKey.currentState?.closeDrawer();
|
kHomeScaffoldKey.currentState?.closeDrawer();
|
||||||
},
|
},
|
||||||
|
onSecondaryTap: () {
|
||||||
|
ref.read(selectedIdStateProvider.notifier).state = id;
|
||||||
|
},
|
||||||
// onDoubleTap: () {
|
// onDoubleTap: () {
|
||||||
// ref.read(selectedIdStateProvider.notifier).state = id;
|
// ref.read(selectedIdStateProvider.notifier).state = id;
|
||||||
// ref.read(selectedIdEditStateProvider.notifier).state = id;
|
// ref.read(selectedIdEditStateProvider.notifier).state = id;
|
||||||
|
@ -69,7 +69,13 @@ class SidebarEnvironmentCard extends StatelessWidget {
|
|||||||
hoverColor: colorVariant,
|
hoverColor: colorVariant,
|
||||||
focusColor: colorVariant.withOpacity(0.5),
|
focusColor: colorVariant.withOpacity(0.5),
|
||||||
onTap: inEditMode ? null : onTap,
|
onTap: inEditMode ? null : onTap,
|
||||||
onSecondaryTap: onSecondaryTap,
|
// onSecondaryTap: onSecondaryTap,
|
||||||
|
onSecondaryTapUp: (isGlobal)
|
||||||
|
? null
|
||||||
|
: (details) {
|
||||||
|
onSecondaryTap?.call();
|
||||||
|
showItemCardMenu(context, details, onMenuSelected);
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 6,
|
left: 6,
|
||||||
@ -90,6 +96,7 @@ class SidebarEnvironmentCard extends StatelessWidget {
|
|||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
onTapOutside: (_) {
|
onTapOutside: (_) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
onTapOutsideNameEditor?.call();
|
onTapOutsideNameEditor?.call();
|
||||||
},
|
},
|
||||||
onFieldSubmitted: (value) {
|
onFieldSubmitted: (value) {
|
||||||
|
@ -71,7 +71,10 @@ class SidebarRequestCard extends StatelessWidget {
|
|||||||
focusColor: colorVariant.withOpacity(0.5),
|
focusColor: colorVariant.withOpacity(0.5),
|
||||||
onTap: inEditMode ? null : onTap,
|
onTap: inEditMode ? null : onTap,
|
||||||
// onDoubleTap: inEditMode ? null : onDoubleTap,
|
// onDoubleTap: inEditMode ? null : onDoubleTap,
|
||||||
onSecondaryTap: onSecondaryTap,
|
onSecondaryTapUp: (details) {
|
||||||
|
onSecondaryTap?.call();
|
||||||
|
showItemCardMenu(context, details, onMenuSelected);
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
left: 6,
|
left: 6,
|
||||||
@ -95,8 +98,8 @@ class SidebarRequestCard extends StatelessWidget {
|
|||||||
//autofocus: true,
|
//autofocus: true,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
onTapOutside: (_) {
|
onTapOutside: (_) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
onTapOutsideNameEditor?.call();
|
onTapOutsideNameEditor?.call();
|
||||||
//FocusScope.of(context).unfocus();
|
|
||||||
},
|
},
|
||||||
onFieldSubmitted: (value) {
|
onFieldSubmitted: (value) {
|
||||||
onTapOutsideNameEditor?.call();
|
onTapOutsideNameEditor?.call();
|
||||||
|
@ -41,3 +41,29 @@ class ItemCardMenu extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Open the item card menu where the right click has been released
|
||||||
|
Future<void> showItemCardMenu(
|
||||||
|
BuildContext context,
|
||||||
|
TapUpDetails details,
|
||||||
|
Function(ItemMenuOption)? onSelected,
|
||||||
|
) async {
|
||||||
|
showMenu(
|
||||||
|
context: context,
|
||||||
|
position: RelativeRect.fromLTRB(
|
||||||
|
details.globalPosition.dx,
|
||||||
|
details.globalPosition.dy,
|
||||||
|
details.globalPosition.dx,
|
||||||
|
details.globalPosition.dy,
|
||||||
|
),
|
||||||
|
items: ItemMenuOption.values
|
||||||
|
.map<PopupMenuEntry<ItemMenuOption>>(
|
||||||
|
(e) => PopupMenuItem<ItemMenuOption>(
|
||||||
|
onTap: () => onSelected?.call(e),
|
||||||
|
value: e,
|
||||||
|
child: Text(e.label),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ import 'package:apidash/screens/settings_page.dart';
|
|||||||
import 'package:apidash/screens/history/history_page.dart';
|
import 'package:apidash/screens/history/history_page.dart';
|
||||||
import 'package:apidash/widgets/widgets.dart';
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
import 'package:extended_text_field/extended_text_field.dart';
|
import 'package:extended_text_field/extended_text_field.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_portal/flutter_portal.dart';
|
import 'package:flutter_portal/flutter_portal.dart';
|
||||||
@ -279,7 +280,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'selectedIdEditStateProvider should not be null after rename button has been tapped',
|
'selectedIdEditStateProvider should not be null after Duplicate button has been tapped',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
ProviderScope(
|
ProviderScope(
|
||||||
@ -304,7 +305,11 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.tap(find.byType(RequestItem));
|
await tester.tap(find.byType(RequestItem));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.tap(find.byIcon(Icons.more_vert).at(1));
|
//await tester.tap(find.byIcon(Icons.more_vert).at(1));
|
||||||
|
await tester.tap(
|
||||||
|
find.byType(RequestItem),
|
||||||
|
buttons: kSecondaryButton,
|
||||||
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Tap on the "Duplicate" option in the menu
|
// Tap on the "Duplicate" option in the menu
|
||||||
|
@ -49,4 +49,32 @@ void main() {
|
|||||||
|
|
||||||
expect(changedValue, ItemMenuOption.duplicate);
|
expect(changedValue, ItemMenuOption.duplicate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('showItemCardMenu shows the menu at the right position',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Builder(
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTapUp: (details) {
|
||||||
|
showItemCardMenu(
|
||||||
|
context, details, (ItemMenuOption option) {});
|
||||||
|
},
|
||||||
|
child: const Text('Show Menu'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text('Show Menu'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
for (var option in ItemMenuOption.values) {
|
||||||
|
expect(find.text(option.label), findsOneWidget);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user