showDesktopTopicActions static method

Future<void> showDesktopTopicActions({
  1. required BuildContext context,
  2. required Offset globalPosition,
  3. required String currentTitle,
  4. required Future<NIMResult> onRename(
    1. String title
    ),
  5. required Future<NIMResult<void>> onDelete(),
  6. bool checkNetwork()?,
})

Implementation

static Future<void> showDesktopTopicActions({
  required BuildContext context,
  required Offset globalPosition,
  required String currentTitle,
  required Future<NIMResult<dynamic>> Function(String title) onRename,
  required Future<NIMResult<void>> Function() onDelete,
  bool Function()? checkNetwork,
}) async {
  final overlay =
      Overlay.of(context).context.findRenderObject() as RenderBox?;
  if (overlay == null) {
    return;
  }
  final action = await material.showMenu<_BotSubsessionAction>(
    context: context,
    position: RelativeRect.fromRect(
      Rect.fromLTWH(globalPosition.dx, globalPosition.dy, 1, 1),
      Offset.zero & overlay.size,
    ),
    shape: material.RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(8),
    ),
    items: [
      material.PopupMenuItem(
        value: _BotSubsessionAction.rename,
        height: 36,
        child: Text(S.of(context).botSubsessionRename),
      ),
      material.PopupMenuItem(
        value: _BotSubsessionAction.delete,
        height: 36,
        child: Text(
          S.of(context).chatMessageActionDelete,
          style: const TextStyle(color: material.Color(0xFFF5222D)),
        ),
      ),
    ],
  );
  if (!context.mounted) {
    return;
  }
  switch (action) {
    case _BotSubsessionAction.rename:
      await _renameTopic(
        context: context,
        currentTitle: currentTitle,
        onRename: onRename,
        checkNetwork: checkNetwork,
      );
      break;
    case _BotSubsessionAction.delete:
      await _deleteTopic(
        context: context,
        onDelete: onDelete,
      );
      break;
    case null:
      break;
  }
}