Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional delete icon to bottom-left corner of elements #33

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/elements/flow_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class FlowElement extends ChangeNotifier {
isDraggable = true,
isResizable = false,
isConnectable = true,
isDeletable = false,
// fixing offset issue under extreme scaling
position = position -
Offset(
Expand Down Expand Up @@ -191,6 +192,9 @@ class FlowElement extends ChangeNotifier {
/// Whether this element can be resized
bool isResizable;

/// Whether this element can be deleted quickly by clicking on the trash icon
bool isDeletable;

/// Whether this element can be connected to others
bool isConnectable;

Expand Down
17 changes: 17 additions & 0 deletions lib/src/ui/element_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class _ElementWidgetState extends State<ElementWidget> {
children: [
element,
if (widget.element.isResizable) _buildResizeHandle(),
if (widget.element.isDeletable) _buildDeleteHandle(),
],
),
),
Expand Down Expand Up @@ -208,6 +209,22 @@ class _ElementWidgetState extends State<ElementWidget> {
);
}

Widget _buildDeleteHandle() {
return Listener(
onPointerUp: (event) {
widget.dashboard.removeElement(widget.element);
},
child: const Align(
alignment: Alignment.bottomLeft,
child: HandlerWidget(
width: 30,
height: 30,
icon: Icon(Icons.delete_outline),
),
),
);
}

Widget _buildDraggableWidget(Widget element) {
return Listener(
onPointerDown: (event) {
Expand Down