sendFileWithConfirmation function

dynamic sendFileWithConfirmation({
  1. required List<XFile> files,
  2. required V2TimConversation conversation,
  3. required ConvType conversationType,
  4. required TUIChatSeparateViewModel model,
  5. required TUITheme theme,
  6. required BuildContext context,
})

Implementation

sendFileWithConfirmation(
    {required List<XFile> files,
    required V2TimConversation conversation,
    required ConvType conversationType,
    required TUIChatSeparateViewModel model,
    required TUITheme theme,
    required BuildContext context}) async {
  bool isCanSend = true;

  if (!PlatformUtils().isWeb) {
    files.map((e) => e.path).any((filePath) {
      final directory = Directory(filePath);
      final isDirectoryExists = directory.existsSync();
      if (isDirectoryExists) {
        isCanSend = false;
        return false;
      }
      return true;
    });
  } else {
    files.map((e) => e.name).any((fileName) {
      String fileExtension = path.extension(fileName);
      bool hasNoExtension = fileExtension.isEmpty;
      if (hasNoExtension) {
        isCanSend = false;
        return false;
      }
      return true;
    });
  }

  if (!isCanSend) {
    TUIKitWidePopup.showSecondaryConfirmDialog(
        text: TIM_t("无法发送,包含文件夹"),
        onConfirm: () {},
        operationKey: TUIKitWideModalOperationKey.unableToSendDueToFolders,
        context: context,
        theme: theme);
    return;
  }

  final option1 = conversation.showName ??
      (conversationType == ConvType.group ? TIM_t("群聊") : TIM_t("对方"));
  TUIKitWidePopup.showPopupWindow(
      operationKey: TUIKitWideModalOperationKey.beforeSendScreenShot,
      context: context,
      isDarkBackground: false,
      width: 600,
      height: files.length < 4 ? 300 : 500,
      title: TIM_t_para("发送给{{option1}}", "发送给$option1")(option1: option1),
      child: (closeFunc) => Container(
            padding: const EdgeInsets.only(bottom: 16),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Scrollbar(
                    child: ListView.separated(
                      itemBuilder: (BuildContext context, int index) {
                        final file = files[index];
                        final fileName = PlatformUtils().isWeb
                            ? file.name
                            : path.basename(file.path);
                        return Material(
                          color: theme.wideBackgroundColor,
                          child: InkWell(
                            onTap: () {
                              launchUrl(Uri.file(file.path));
                            },
                            child: Padding(
                              padding: const EdgeInsets.symmetric(
                                  vertical: 6, horizontal: 20),
                              child: Row(
                                children: [
                                  TIMUIKitFileIcon(
                                    size: 44,
                                    fileFormat: fileName.split(
                                        ".")[fileName.split(".").length - 1],
                                  ),
                                  const SizedBox(width: 16),
                                  Expanded(
                                    child: Text(
                                      fileName,
                                      style: TextStyle(
                                          fontSize: 16,
                                          color: theme.darkTextColor),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        );
                      },
                      separatorBuilder: (BuildContext context, int index) {
                        return Divider(
                          height: 1,
                          thickness: 1,
                          color: theme.weakDividerColor,
                        );
                      },
                      itemCount: files.length,
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(right: 16, top: 16),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      OutlinedButton(
                          onPressed: () {
                            closeFunc();
                          },
                          child: Text(TIM_t("取消"))),
                      const SizedBox(
                        width: 20,
                      ),
                      ElevatedButton(
                          onPressed: () {
                            sendFiles(files, model, conversation,
                                conversationType, context);
                            closeFunc();
                          },
                          child: Text(TIM_t("发送")))
                    ],
                  ),
                )
              ],
            ),
          ));
}