diff --git a/lib/consts.dart b/lib/consts.dart index e96bb011..77d4d292 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -302,6 +302,13 @@ enum ItemMenuOption { final String label; } +enum SidebarMenuOption { + import("Import"); + + const SidebarMenuOption(this.label); + final String label; +} + enum HTTPVerb { get, head, post, put, patch, delete } enum FormDataType { text, file } @@ -685,7 +692,7 @@ const kRaiseIssue = const kHintTextUrlCard = "Enter API endpoint like https://$kDefaultUri/"; const kLabelPlusNew = "+ New"; -const kLabelImport = "Import"; +const kLabelMoreOptions = "More Options"; const kLabelSend = "Send"; const kLabelSending = "Sending.."; const kLabelBusy = "Busy"; diff --git a/lib/screens/common_widgets/sidebar_header.dart b/lib/screens/common_widgets/sidebar_header.dart index db7ed9ee..4e6b16f7 100644 --- a/lib/screens/common_widgets/sidebar_header.dart +++ b/lib/screens/common_widgets/sidebar_header.dart @@ -2,13 +2,18 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/extensions/extensions.dart'; +import 'package:apidash/widgets/widgets.dart'; import 'package:apidash/consts.dart'; import 'sidebar_save_button.dart'; class SidebarHeader extends ConsumerWidget { - const SidebarHeader({super.key, this.onAddNew, this.onImport}); - final Function()? onAddNew; - final Function()? onImport; + const SidebarHeader({ + super.key, + this.onAddNew, + this.onImport, + }); + final VoidCallback? onAddNew; + final VoidCallback? onImport; @override Widget build(BuildContext context, WidgetRef ref) { @@ -28,13 +33,14 @@ class SidebarHeader extends ConsumerWidget { style: kTextStyleButton, ), ), - kHSpacer12, - ElevatedButton( - onPressed: onImport, - style: kButtonSidebarStyle, - child: const Text( - kLabelImport, - style: kTextStyleButton, + kHSpacer4, + SizedBox( + width: 24, + child: SidebarTopMenu( + tooltip: kLabelMoreOptions, + onSelected: (option) => switch (option) { + SidebarMenuOption.import => onImport?.call(), + }, ), ), context.width <= kMinWindowSize.width diff --git a/lib/widgets/menu_sidebar_top.dart b/lib/widgets/menu_sidebar_top.dart new file mode 100644 index 00000000..0f1ced58 --- /dev/null +++ b/lib/widgets/menu_sidebar_top.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:apidash/consts.dart'; + +class SidebarTopMenu extends StatelessWidget { + const SidebarTopMenu({ + super.key, + this.onSelected, + this.child, + this.offset = Offset.zero, + this.splashRadius = 14, + this.tooltip, + this.shape, + }); + final Widget? child; + final Offset offset; + final double splashRadius; + final String? tooltip; + final ShapeBorder? shape; + + final Function(SidebarMenuOption)? onSelected; + + @override + Widget build(BuildContext context) { + return PopupMenuButton( + tooltip: tooltip, + padding: EdgeInsets.zero, + splashRadius: splashRadius, + icon: const Icon(Icons.more_vert), + iconSize: 14, + offset: offset, + onSelected: onSelected, + shape: shape, + itemBuilder: (BuildContext context) => SidebarMenuOption.values + .map>( + (e) => PopupMenuItem( + value: e, + child: Text(e.label), + ), + ) + .toList(), + child: child, + ); + } +} diff --git a/lib/widgets/widgets.dart b/lib/widgets/widgets.dart index a180a27e..cfc23ea1 100644 --- a/lib/widgets/widgets.dart +++ b/lib/widgets/widgets.dart @@ -31,6 +31,7 @@ export 'intro_message.dart'; export 'json_previewer.dart'; export 'markdown.dart'; export 'menu_item_card.dart'; +export 'menu_sidebar_top.dart'; export 'overlay_widget.dart'; export 'popup_menu_codegen.dart'; export 'popup_menu_env.dart';