Skip to main content

LMFeedMenu

LMFeedMenu is a widget that represents the menu section of a post or comment in a feed. It provides a customizable popup menu with various menu items and actions associated with each item. The menu can be used to perform actions such as deleting, pinning, unpinning, reporting, or editing a post or comment.


LMFeedMenu

The LMFeedMenu widget is a part of the likeminds_feed_flutter_ui package. It is designed to be used within an LMFeedPostWidget or LMFeedCommentWidget to provide a context menu for posts and comments.

Properties

  • menuItems (List<LMPopUpMenuItemViewData>) - Required

The list of menu items to be displayed in the popup menu. This is a required parameter.

  • isFeed (bool) - Required

A flag indicating whether the menu is being used in a feed context. This is a required parameter.

  • children (Map<int, Widget>)

A map of custom widgets to be displayed for specific menu item IDs. The keys of the map correspond to the menu item IDs, and the values are the custom widgets to be displayed. This is an optional parameter.

  • menuIcon (LMFeedIcon)

The icon widget to be displayed as the trigger for the popup menu. If not provided, a default icon will be used. This is an optional parameter.

  • removeItemIds (Set<int>)

A set of menu item IDs that should be removed from the menu. This is useful for excluding certain menu items based on specific conditions. This is an optional parameter with a default value of {4, 7}.

  • action (LMFeedMenuAction)

An instance of LMFeedMenuAction that defines the callbacks for various menu item actions. This is an optional parameter.

Usage Example

LMFeedMenu(
menuItems: [
LMPopUpMenuItemViewData(id: 1, title: "Delete"),
LMPopUpMenuItemViewData(id: 2, title: "Pin"),
LMPopUpMenuItemViewData(id: 3, title: "Unpin"),
LMPopUpMenuItemViewData(id: 4, title: "Report"),
LMPopUpMenuItemViewData(id: 5, title: "Edit"),
],
isFeed: true,
children: {
1: Row(
children: [
Icon(Icons.delete),
SizedBox(width: 8),
Text("Delete"),
],
),
5: Row(
children: [
Icon(Icons.edit),
SizedBox(width: 8),
Text("Edit"),
],
),
},
menuIcon: LMFeedIcon(
type: LMFeedIconType.svg,
assetPath: "assets/icons/menu.svg",
),
removeItemIds: {4},
action: LMFeedMenuAction(
onPostDelete: () {
// Handle post delete action
print("Post deleted");
},
onPostPin: () {
// Handle post pin action
print("Post pinned");
},
onPostUnpin: () {
// Handle post unpin action
print("Post unpinned");
},
onPostEdit: () {
// Handle post edit action
print("Post edited");
},
),
)

In this example, an LMFeedMenu widget is created with a list of menu items specified using LMPopUpMenuItemViewData. The isFeed property is set to true to indicate that the menu is being used in a feed context. Custom widgets are provided for the "Delete" and "Edit" menu items using the children property. The menuIcon property is used to specify a custom icon for the menu trigger. The removeItemIds property is used to exclude the "Report" menu item. The action property is used to define the callbacks for various menu item actions, such as deleting, pinning, unpinning, and editing a post.