TF-2644 Handle total size exceeded maximum size when drag & drop multiple file to composer
This commit is contained in:
@@ -4,7 +4,8 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/exceptions/pick_file_exception.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/extensions/platform_file_extension.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/state/local_file_picker_state.dart';
|
||||
|
||||
class LocalFilePickerInteractor {
|
||||
@@ -13,23 +14,22 @@ class LocalFilePickerInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute({FileType fileType = FileType.any}) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LocalFilePickerLoading());
|
||||
|
||||
final filesResult = await FilePicker.platform.pickFiles(
|
||||
type: fileType,
|
||||
allowMultiple: true,
|
||||
withData: PlatformInfo.isWeb
|
||||
withData: PlatformInfo.isWeb,
|
||||
withReadStream: PlatformInfo.isMobile
|
||||
);
|
||||
if (filesResult != null && filesResult.files.isNotEmpty) {
|
||||
final fileInfoResults = filesResult.files
|
||||
.map((platformFile) => FileInfo(
|
||||
platformFile.name,
|
||||
PlatformInfo.isWeb ? '' : platformFile.path ?? '',
|
||||
platformFile.size,
|
||||
bytes: PlatformInfo.isWeb ? platformFile.bytes : null
|
||||
))
|
||||
.toList();
|
||||
yield Right<Failure, Success>(LocalFilePickerSuccess(fileInfoResults));
|
||||
|
||||
if (filesResult?.files.isNotEmpty == true) {
|
||||
final listFileInfo = filesResult!.files
|
||||
.map((platformFile) => platformFile.toFileInfo())
|
||||
.toList();
|
||||
yield Right<Failure, Success>(LocalFilePickerSuccess(listFileInfo));
|
||||
} else {
|
||||
yield Left<Failure, Success>(LocalFilePickerCancel());
|
||||
yield Left<Failure, Success>(LocalFilePickerFailure(PickFileCanceledException()));
|
||||
}
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(LocalFilePickerFailure(exception));
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/exceptions/pick_file_exception.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/extensions/platform_file_extension.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/state/local_image_picker_state.dart';
|
||||
|
||||
class LocalImagePickerInteractor {
|
||||
|
||||
LocalImagePickerInteractor();
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LocalImagePickerLoading());
|
||||
|
||||
final filePickerResult = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
withReadStream: PlatformInfo.isMobile,
|
||||
withData: PlatformInfo.isWeb
|
||||
);
|
||||
|
||||
if (filePickerResult?.files.isNotEmpty == true) {
|
||||
final fileInfo = filePickerResult!.files.first.toFileInfo();
|
||||
yield Right<Failure, Success>(LocalImagePickerSuccess(fileInfo));
|
||||
} else {
|
||||
yield Left<Failure, Success>(LocalImagePickerFailure(PickFileCanceledException()));
|
||||
}
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(LocalImagePickerFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user