TF-56 Implement local file picker
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import 'package:core/core.dart';
|
||||||
|
import 'package:model/model.dart';
|
||||||
|
|
||||||
|
class LocalFilePickerSuccess extends UIState {
|
||||||
|
final FileInfo fileInfo;
|
||||||
|
|
||||||
|
LocalFilePickerSuccess(this.fileInfo);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [fileInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalFilePickerFailure extends FeatureFailure {
|
||||||
|
final exception;
|
||||||
|
|
||||||
|
LocalFilePickerFailure(this.exception);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [exception];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalFilePickerCancel extends FeatureFailure {
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
|
import 'package:model/model.dart';
|
||||||
|
import 'package:tmail_ui_user/features/upload/domain/state/local_file_picker_state.dart';
|
||||||
|
|
||||||
|
class LocalFilePickerInteractor {
|
||||||
|
|
||||||
|
LocalFilePickerInteractor();
|
||||||
|
|
||||||
|
Stream<Either<Failure, Success>> execute({FileType fileType = FileType.any}) async* {
|
||||||
|
try {
|
||||||
|
final filesResult = await FilePicker.platform.pickFiles(type: fileType);
|
||||||
|
if (filesResult != null && filesResult.files.isNotEmpty) {
|
||||||
|
final platformFile = filesResult.files.first;
|
||||||
|
final fileInfoResult = FileInfo(
|
||||||
|
platformFile.name,
|
||||||
|
platformFile.path ?? '',
|
||||||
|
platformFile.size,
|
||||||
|
);
|
||||||
|
yield Right<Failure, Success>(LocalFilePickerSuccess(fileInfoResult));
|
||||||
|
} else {
|
||||||
|
yield Left<Failure, Success>(LocalFilePickerCancel());
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
yield Left<Failure, Success>(LocalFilePickerFailure(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user