getSelectedNodesButtons method

List<Widget> getSelectedNodesButtons(
  1. IMindMapNode node
)

Implementation

List<Widget> getSelectedNodesButtons(IMindMapNode node) {
  List<Widget> list = [];
  if (widget.getMindMap()?.getFishboneMapType() ==
      FishboneMapType.rightToLeft) {
    if (node.getNodeType() == NodeType.root) {
      if (!(widget.getMindMap()?.getReadOnly() ?? false)) {
        list.add(
          Positioned(
            left:
                node.getFishbonePosition().dx -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) + 12),
            top:
                node.getFishbonePosition().dy +
                (node.getSize()?.height ?? 0) / 2 -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) + 12) / 2,
            child: SizedBox(
              width: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              height: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              child: Center(
                //add button
                child: Container(
                  constraints: BoxConstraints(
                    maxWidth: (widget.getMindMap()?.getButtonWidth() ?? 24)
                        .toDouble(),
                    maxHeight: (widget.getMindMap()?.getButtonWidth() ?? 24)
                        .toDouble(),
                  ),
                  decoration: BoxDecoration(
                    color:
                        (widget.getMindMap()?.getButtonBackground() ??
                        Colors.white),
                    border: Border.all(
                      color:
                          (widget.getMindMap()?.getButtonColor() ??
                          Colors.black),
                      width: 1,
                    ),
                    borderRadius: BorderRadius.circular(
                      (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                    ),
                  ),
                  child: IconButton(
                    onPressed: () {
                      IMindMapNode newnode = MindMapNode()
                        ..setTitle("New Node");
                      if (node.getLeftItems().isEmpty) {
                        node.addRightItem(newnode);
                      } else {
                        node.insertLeftItem(newnode, 0);
                      }
                      widget.getMindMap()?.setSelectedNode(newnode);
                      node.refresh();
                    },
                    padding: EdgeInsets.zero,
                    hoverColor: Colors.green.shade200,
                    highlightColor: Colors.green,
                    icon: Icon(
                      Icons.add_rounded,
                      size: (widget.getMindMap()?.getButtonWidth() ?? 24) - 6,
                      color:
                          (widget.getMindMap()?.getButtonColor() ??
                          Colors.black),
                    ),
                  ),
                ),
              ),
            ),
          ),
        );
      }
    } else {
      if (!(widget.getMindMap()?.getReadOnly() ?? false)) {
        list.add(
          Positioned(
            left:
                node.getFishbonePosition().dx -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) * 3 + 12 * 4),
            top:
                node.getFishbonePosition().dy +
                (node.getSize()?.height ?? 0) / 2 -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) + 12) / 2,
            child: SizedBox(
              width:
                  (widget.getMindMap()?.getButtonWidth() ?? 24) * 3 + 12 * 4,
              height: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  ///add Add Button
                  Container(
                    constraints: BoxConstraints(
                      maxWidth: (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                      maxHeight: (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                    ),
                    decoration: BoxDecoration(
                      color:
                          (widget.getMindMap()?.getButtonBackground() ??
                          Colors.white),
                      border: Border.all(
                        color:
                            (widget.getMindMap()?.getButtonColor() ??
                            Colors.black),
                        width: 1,
                      ),
                      borderRadius: BorderRadius.circular(
                        (widget.getMindMap()?.getButtonWidth() ?? 24)
                            .toDouble(),
                      ),
                    ),
                    child: IconButton(
                      onPressed: () {
                        widget._focusNode.unfocus();
                        if (node.getNodeType() == NodeType.left) {
                          node.addLeftItem(
                            MindMapNode()..setTitle("New Node"),
                          );
                        } else {
                          node.addRightItem(
                            MindMapNode()..setTitle("New Node"),
                          );
                        }
                        widget.getMindMap()?.onChanged();
                      },
                      padding: EdgeInsets.zero,
                      hoverColor: Colors.green.shade200,
                      highlightColor: Colors.green,
                      icon: Icon(
                        Icons.add_rounded,
                        size:
                            (widget.getMindMap()?.getButtonWidth() ?? 24) - 6,
                        color:
                            (widget.getMindMap()?.getButtonColor() ??
                            Colors.black),
                      ),
                    ),
                  ),

                  ///Sapce
                  (widget.getMindMap()?.getShowRecycle() ?? false)
                      ? SizedBox(width: 0, height: 0)
                      : SizedBox(width: 6),

                  ///Delete Button
                  (widget.getMindMap()?.getShowRecycle() ?? false)
                      ? SizedBox(width: 0, height: 0)
                      : Container(
                          constraints: BoxConstraints(
                            maxWidth:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                            maxHeight:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                          ),
                          decoration: BoxDecoration(
                            color:
                                (widget.getMindMap()?.getButtonBackground() ??
                                Colors.white),
                            border: Border.all(
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                              width: 1,
                            ),
                            borderRadius: BorderRadius.circular(
                              (widget.getMindMap()?.getButtonWidth() ?? 24)
                                  .toDouble(),
                            ),
                          ),
                          child: IconButton(
                            onPressed: () {
                              showDialog(
                                context: context,
                                builder: (context) {
                                  return AlertDialog(
                                    content: Text(
                                      widget
                                              .getMindMap()
                                              ?.getDeleteNodeString() ??
                                          "Delete this node?",
                                    ),
                                    actions: [
                                      TextButton(
                                        child: Text(
                                          widget
                                                  .getMindMap()
                                                  ?.getCancelString() ??
                                              "Cancel",
                                        ),
                                        onPressed: () {
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                      TextButton(
                                        child: Text(
                                          widget
                                                  .getMindMap()
                                                  ?.getOkString() ??
                                              "OK",
                                        ),
                                        onPressed: () {
                                          node
                                              .getParentNode()
                                              ?.removeLeftItem(node);

                                          node
                                              .getParentNode()
                                              ?.removeRightItem(node);

                                          widget
                                              .getMindMap()
                                              ?.setSelectedNode(null);
                                          widget
                                              .getMindMap()
                                              ?.getRootNode()
                                              .refresh();
                                          widget.getMindMap()?.onChanged();
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                    ],
                                  );
                                },
                              );
                            },
                            hoverColor: Colors.red.shade200,
                            highlightColor: Colors.red,
                            padding: EdgeInsets.zero,
                            icon: Icon(
                              Icons.close_rounded,
                              size:
                                  (widget.getMindMap()?.getButtonWidth() ??
                                      24) -
                                  6,
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                            ),
                          ),
                        ),

                  ///Space
                  !(widget.getMindMap()?.hasTextField() ?? true) &&
                          (widget.getMindMap()?.hasEditButton() ?? false)
                      ? SizedBox(width: 6)
                      : SizedBox(width: 0),

                  ///Edit Button
                  !(widget.getMindMap()?.hasTextField() ?? true) &&
                          (widget.getMindMap()?.hasEditButton() ?? false)
                      ? Container(
                          constraints: BoxConstraints(
                            maxWidth:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                            maxHeight:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                          ),
                          decoration: BoxDecoration(
                            color:
                                (widget.getMindMap()?.getButtonBackground() ??
                                Colors.white),
                            border: Border.all(
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                              width: 1,
                            ),
                            borderRadius: BorderRadius.circular(
                              (widget.getMindMap()?.getButtonWidth() ?? 24)
                                  .toDouble(),
                            ),
                          ),
                          child: IconButton(
                            onPressed: () {
                              widget.getMindMap()?.onEdit(node);
                            },
                            hoverColor: Colors.blue.shade200,
                            highlightColor: Colors.blue,
                            padding: EdgeInsets.zero,
                            icon: Icon(
                              Icons.edit_outlined,
                              size:
                                  (widget.getMindMap()?.getButtonWidth() ??
                                      24) -
                                  8,
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                            ),
                          ),
                        )
                      : SizedBox(width: 0, height: 0),

                  ///Sapce
                  SizedBox(width: 6),
                ],
              ),
            ),
          ),
        );
      }
    }
  } else {
    if (node.getNodeType() == NodeType.root) {
      if (!(widget.getMindMap()?.getReadOnly() ?? false)) {
        list.add(
          Positioned(
            left:
                node.getFishbonePosition().dx + (node.getSize()?.width ?? 0),
            top:
                node.getFishbonePosition().dy +
                (node.getSize()?.height ?? 0) / 2 -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) + 12) / 2,
            child: SizedBox(
              width: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              height: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              child: Center(
                //Add button
                child: Container(
                  constraints: BoxConstraints(
                    maxWidth: (widget.getMindMap()?.getButtonWidth() ?? 24)
                        .toDouble(),
                    maxHeight: (widget.getMindMap()?.getButtonWidth() ?? 24)
                        .toDouble(),
                  ),
                  decoration: BoxDecoration(
                    color:
                        (widget.getMindMap()?.getButtonBackground() ??
                        Colors.white),
                    border: Border.all(
                      color:
                          (widget.getMindMap()?.getButtonColor() ??
                          Colors.black),
                      width: 1,
                    ),
                    borderRadius: BorderRadius.circular(
                      (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                    ),
                  ),
                  child: IconButton(
                    onPressed: () {
                      IMindMapNode newnode = MindMapNode()
                        ..setTitle("New Node");
                      if (node.getLeftItems().isEmpty) {
                        node.addRightItem(newnode);
                      } else {
                        node.insertLeftItem(newnode, 0);
                      }
                      widget.getMindMap()?.setSelectedNode(newnode);
                      node.refresh();
                    },
                    padding: EdgeInsets.zero,
                    hoverColor: Colors.green.shade200,
                    highlightColor: Colors.green,
                    icon: Icon(
                      Icons.add_rounded,
                      size: (widget.getMindMap()?.getButtonWidth() ?? 24) - 6,
                      color:
                          (widget.getMindMap()?.getButtonColor() ??
                          Colors.black),
                    ),
                  ),
                ),
              ),
            ),
          ),
        );
      }
    } else {
      if (!(widget.getMindMap()?.getReadOnly() ?? false)) {
        list.add(
          Positioned(
            left:
                node.getFishbonePosition().dx + (node.getSize()?.width ?? 0),
            top:
                node.getFishbonePosition().dy +
                (node.getSize()?.height ?? 0) / 2 -
                ((widget.getMindMap()?.getButtonWidth() ?? 24) + 12) / 2,
            child: SizedBox(
              width:
                  (widget.getMindMap()?.getButtonWidth() ?? 24) * 3 + 12 * 4,
              height: (widget.getMindMap()?.getButtonWidth() ?? 24) + 12,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  ///Sapce
                  SizedBox(width: 6),

                  ///Edit Button
                  !(widget.getMindMap()?.hasTextField() ?? true) &&
                          (widget.getMindMap()?.hasEditButton() ?? false)
                      ? Container(
                          constraints: BoxConstraints(
                            maxWidth:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                            maxHeight:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                          ),
                          decoration: BoxDecoration(
                            color:
                                (widget.getMindMap()?.getButtonBackground() ??
                                Colors.white),
                            border: Border.all(
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                              width: 1,
                            ),
                            borderRadius: BorderRadius.circular(
                              (widget.getMindMap()?.getButtonWidth() ?? 24)
                                  .toDouble(),
                            ),
                          ),
                          child: IconButton(
                            onPressed: () {
                              widget.getMindMap()?.onEdit(node);
                            },
                            hoverColor: Colors.blue.shade200,
                            highlightColor: Colors.blue,
                            padding: EdgeInsets.zero,
                            icon: Icon(
                              Icons.edit_outlined,
                              size:
                                  (widget.getMindMap()?.getButtonWidth() ??
                                      24) -
                                  8,
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                            ),
                          ),
                        )
                      : SizedBox(width: 0, height: 0),

                  ///Space
                  !(widget.getMindMap()?.hasTextField() ?? true) &&
                          (widget.getMindMap()?.hasEditButton() ?? false)
                      ? SizedBox(width: 6)
                      : SizedBox(width: 0),

                  ///Delete Button
                  (widget.getMindMap()?.getShowRecycle() ?? false)
                      ? SizedBox(width: 0, height: 0)
                      : Container(
                          constraints: BoxConstraints(
                            maxWidth:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                            maxHeight:
                                (widget.getMindMap()?.getButtonWidth() ?? 24)
                                    .toDouble(),
                          ),
                          decoration: BoxDecoration(
                            color:
                                (widget.getMindMap()?.getButtonBackground() ??
                                Colors.white),
                            border: Border.all(
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                              width: 1,
                            ),
                            borderRadius: BorderRadius.circular(
                              (widget.getMindMap()?.getButtonWidth() ?? 24)
                                  .toDouble(),
                            ),
                          ),
                          child: IconButton(
                            onPressed: () {
                              showDialog(
                                context: context,
                                builder: (context) {
                                  return AlertDialog(
                                    content: Text(
                                      widget
                                              .getMindMap()
                                              ?.getDeleteNodeString() ??
                                          "Delete this node?",
                                    ),
                                    actions: [
                                      TextButton(
                                        child: Text(
                                          widget
                                                  .getMindMap()
                                                  ?.getCancelString() ??
                                              "Cancel",
                                        ),
                                        onPressed: () {
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                      TextButton(
                                        child: Text(
                                          widget
                                                  .getMindMap()
                                                  ?.getOkString() ??
                                              "OK",
                                        ),
                                        onPressed: () {
                                          node
                                              .getParentNode()
                                              ?.removeLeftItem(node);

                                          node
                                              .getParentNode()
                                              ?.removeRightItem(node);

                                          widget
                                              .getMindMap()
                                              ?.setSelectedNode(null);
                                          widget
                                              .getMindMap()
                                              ?.getRootNode()
                                              .refresh();
                                          widget.getMindMap()?.onChanged();
                                          Navigator.of(context).pop();
                                        },
                                      ),
                                    ],
                                  );
                                },
                              );
                            },
                            hoverColor: Colors.red.shade200,
                            highlightColor: Colors.red,
                            padding: EdgeInsets.zero,
                            icon: Icon(
                              Icons.close_rounded,
                              size:
                                  (widget.getMindMap()?.getButtonWidth() ??
                                      24) -
                                  6,
                              color:
                                  (widget.getMindMap()?.getButtonColor() ??
                                  Colors.black),
                            ),
                          ),
                        ),

                  ///Sapce
                  (widget.getMindMap()?.getShowRecycle() ?? false)
                      ? SizedBox(width: 0, height: 0)
                      : SizedBox(width: 6),

                  ///add Add Button
                  Container(
                    constraints: BoxConstraints(
                      maxWidth: (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                      maxHeight: (widget.getMindMap()?.getButtonWidth() ?? 24)
                          .toDouble(),
                    ),
                    decoration: BoxDecoration(
                      color:
                          (widget.getMindMap()?.getButtonBackground() ??
                          Colors.white),
                      border: Border.all(
                        color:
                            (widget.getMindMap()?.getButtonColor() ??
                            Colors.black),
                        width: 1,
                      ),
                      borderRadius: BorderRadius.circular(
                        (widget.getMindMap()?.getButtonWidth() ?? 24)
                            .toDouble(),
                      ),
                    ),
                    child: IconButton(
                      onPressed: () {
                        widget._focusNode.unfocus();
                        if (node.getNodeType() == NodeType.left) {
                          node.addLeftItem(
                            MindMapNode()..setTitle("New Node"),
                          );
                        } else {
                          node.addRightItem(
                            MindMapNode()..setTitle("New Node"),
                          );
                        }
                        widget.getMindMap()?.onChanged();
                      },
                      padding: EdgeInsets.zero,
                      hoverColor: Colors.green.shade200,
                      highlightColor: Colors.green,
                      icon: Icon(
                        Icons.add_rounded,
                        size:
                            (widget.getMindMap()?.getButtonWidth() ?? 24) - 6,
                        color:
                            (widget.getMindMap()?.getButtonColor() ??
                            Colors.black),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
  }
  return list;
}