imageUpload method

Future<void> imageUpload(
  1. dynamic context,
  2. ValueChanged<UploadResultEntity> changed,
  3. String parentId, {
  4. IPFSFileType fileType = IPFSFileType.image,
  5. CommonSortPathDelegate? sortPathDelegate,
  6. Function? progressCallback,
})

图片或者视频等选择 @param changed 上传之后的内容 @param parentId 文件夹的ID @param fileType 文件类型

Implementation

Future<void> imageUpload(
    context, ValueChanged<UploadResultEntity> changed, String parentId,
    {IPFSFileType fileType = IPFSFileType.image,
    CommonSortPathDelegate? sortPathDelegate,
    Function? progressCallback}) async {
  print(fileType);
  RequestType requestType = RequestType.image;
  if (fileType == IPFSFileType.image) {
    requestType = RequestType.image;
  } else if (fileType == IPFSFileType.audio) {
    requestType = RequestType.audio;
  } else if (fileType == IPFSFileType.video) {
    requestType = RequestType.video;
  } else if (fileType == IPFSFileType.media) {
    requestType = RequestType.all;
  } else if (fileType == IPFSFileType.imageAndVideo) {
    requestType = RequestType.common;
  }
  const AssetPickerTextDelegate textDelegate = AssetPickerTextDelegate();
  List<AssetEntity>? image = await AssetPicker.pickAssets(context,
      pickerConfig: AssetPickerConfig(
        maxAssets: 1,
        requestType: requestType,
        specialItemPosition: SpecialItemPosition.prepend,
        specialItemBuilder: (
          BuildContext context,
          AssetPathEntity? path,
          int length,
        ) {
          if (path?.isAll != true) {
            return null;
          }

          return Semantics(
            label: textDelegate.sActionUseCameraHint,
            button: true,
            image:true,
            onTapHint: textDelegate.sActionUseCameraHint,
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () async {
                Feedback.forTap(context);
                final AssetEntity? result = await _pickFromCamera(context);
                if (result != null) {
                  File? file = await result.loadFile();
                  String filePath = file?.path??'';
                  if (filePath.isEmpty) {
                    ToastUtils.show('文件不存在,请重新选择');
                    return;
                  }
                  voneFileUpload(context, filePath, changed, parentId,
                      progressCallback: progressCallback);
                  Navigator.pop(context);
                }
              },
              child: const Center(
                child: Icon(Icons.camera_enhance, size: 42.0),
              ),
            ),
          );
        },
        sortPathDelegate: sortPathDelegate,
      ));
  if (image != null && image.isNotEmpty) {
    File? file = await image[0].loadFile();
    if (file != null) {
      String filePath = file.path;
      if (filePath.isEmpty) {
        ToastUtils.show('选择的文件不存在,请重新选择');
        return;
      }
      voneFileUpload(context, filePath, changed, parentId,
          progressCallback: progressCallback);
    } else {
      ToastUtils.show('选择的文件不存在,请重新选择');
    }
  }
}