showButtonMenu method

void showButtonMenu()

Implementation

void showButtonMenu() {
  final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
  final RenderBox button = context.findRenderObject()! as RenderBox;
  final RenderBox overlay =
      Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox;
  final Offset offset = Offset(0.0, button.size.height - (8 / 2));
  final RelativeRect position = RelativeRect.fromRect(
    Rect.fromPoints(
      button.localToGlobal(offset, ancestor: overlay),
      button.localToGlobal(button.size.bottomRight(Offset.zero) + offset,
          ancestor: overlay),
    ),
    Offset.zero & overlay.size,
  );
  var activeUsers = widget.activeUsers
      ?.map((e) => AppPopupMenuItem(
            text: e.displayName,
            onTap: () {
              widget.onActiveUserSelected?.call(e);
              setState(() {
                widget.textEditingController.text = "@${e.displayName} ";
              });
            },
            show: false,
          ))
      .toList();
  var mutedUsers = widget.mutedUsers
      ?.map((e) => AppPopupMenuItem(
            show: true,
            text: e.displayName,
            onTap: () {
              showDialog<Text>(
                  context: context,
                  builder: (ctx) => AlertDialog(
                        contentPadding: EdgeInsets.zero,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(7.0),
                        ),
                        content: SizedBox(
                          height: 100,
                          width: 50,
                          child: Padding(
                            padding: const EdgeInsets.only(top: 10.0),
                            child: Column(
                              children: [
                                Text(
                                  'Unmute ${e.displayName}',
                                  style: const TextStyle(
                                      fontSize: 18,
                                      fontWeight: FontWeight.bold,
                                      color: Colors.black),
                                ),
                                const SizedBox(height: 15),
                                Row(
                                  children: [
                                    const Spacer(),
                                    TextButton(
                                        onPressed: () {
                                          Navigator.of(ctx).pop();
                                        },
                                        child: const Text(
                                          'Disagree',
                                          style: TextStyle(
                                              color: Colors.black,
                                              fontWeight: FontWeight.bold),
                                        )),
                                    const SizedBox(width: 50),
                                    TextButton(
                                        onPressed: () {
                                          setState(() {
                                            // // widget.currentUserManager.unBlockUser(userId: e.id);
                                            // for (int i = 0;
                                            //     i < widget.mutedUsers!.length;
                                            //     i++) {
                                            //   if (widget.mutedUsers![i].id
                                            //       .toLowerCase()
                                            //       .contains(
                                            //           e.id.toLowerCase())) {
                                            //     widget.mutedUsers !=
                                            //         widget.mutedUsers!.remove(
                                            //             widget
                                            //                 .mutedUsers![i]);
                                            //   }
                                            // }
                                            //
                                            // Navigator.of(ctx).pop();
                                          });
                                        },
                                        child: const Text(
                                          'Agree',
                                          style: TextStyle(
                                              color: Colors.greenAccent,
                                              fontWeight: FontWeight.bold),
                                        )),
                                  ],
                                )
                              ],
                            ),
                          ),
                        ),
                      ));
            },
            //   onTap: (){  setState(() => widget.currentUserManager.unBlockUser(userId: e.id));},
          ))
      .toList();
  if (activeUsers!.isNotEmpty || mutedUsers!.isNotEmpty) {
    showMenu<T?>(
      activeUsers: activeUsers,
      mutedUsers: mutedUsers!,
      context: context,
      elevation: popupMenuTheme.elevation,
      position: position,
      shape: popupMenuTheme.shape,
      color: popupMenuTheme.color,
    ).then<void>((T? newValue) {
      if (!mounted) return null;
      if (newValue == null) {
        widget.onCanceled?.call();
        return null;
      }
    });
  }
}