ui: Move file picker invocation to the SendFiles bloc
This commit is contained in:
parent
cf8180d587
commit
222521f3f7
@ -291,15 +291,8 @@ class ConversationBloc extends Bloc<ConversationEvent, ConversationState> {
|
||||
}
|
||||
|
||||
Future<void> _onFileUploadRequested(FileUploadRequestedEvent event, Emitter<ConversationState> emit) async {
|
||||
final result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: true);
|
||||
|
||||
if (result != null) {
|
||||
GetIt.I.get<SendFilesBloc>().add(
|
||||
SendFilesPageRequestedEvent(
|
||||
result.files.map((PlatformFile file) => file.path!).toList(),
|
||||
state.conversation!.jid,
|
||||
),
|
||||
);
|
||||
}
|
||||
GetIt.I.get<SendFilesBloc>().add(
|
||||
SendFilesPageRequestedEvent(state.conversation!.jid),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,29 @@ class SendFilesBloc extends Bloc<SendFilesEvent, SendFilesState> {
|
||||
on<FileSendingRequestedEvent>(_onFileSendingRequested);
|
||||
}
|
||||
|
||||
/// Pick files. Returns either a list of paths to attach or null if the process has
|
||||
/// been cancelled.
|
||||
Future<List<String>?> _pickFiles() async {
|
||||
// TODO(PapaTutuWawa): Allow multiple file types
|
||||
final result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: true);
|
||||
|
||||
if (result == null) return null;
|
||||
|
||||
return result.files.map((PlatformFile file) => file.path!).toList();
|
||||
}
|
||||
|
||||
Future<void> _sendFilesRequested(SendFilesPageRequestedEvent event, Emitter<SendFilesState> emit) async {
|
||||
final files = await _pickFiles();
|
||||
if (files == null) return;
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
files: event.files,
|
||||
files: files,
|
||||
index: 0,
|
||||
conversationJid: event.jid,
|
||||
),
|
||||
);
|
||||
|
||||
GetIt.I.get<NavigationBloc>().add(
|
||||
PushedNamedEvent(
|
||||
const NavigationDestination(
|
||||
@ -41,18 +56,14 @@ class SendFilesBloc extends Bloc<SendFilesEvent, SendFilesState> {
|
||||
}
|
||||
|
||||
Future<void> _onAddFilesRequested(AddFilesRequestedEvent event, Emitter<SendFilesState> emit) async {
|
||||
final result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: true);
|
||||
final files = await _pickFiles();
|
||||
if (files == null) return;
|
||||
|
||||
if (result != null) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
files: List.from(state.files)
|
||||
..addAll(
|
||||
result.files.map((PlatformFile file) => file.path!).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
emit(
|
||||
state.copyWith(
|
||||
files: List.from(state.files)..addAll(files),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onFileSendingRequested(FileSendingRequestedEvent event, Emitter<SendFilesState> emitter) async {
|
||||
|
@ -4,8 +4,7 @@ abstract class SendFilesEvent {}
|
||||
|
||||
class SendFilesPageRequestedEvent extends SendFilesEvent {
|
||||
|
||||
SendFilesPageRequestedEvent(this.files, this.jid);
|
||||
final List<String> files;
|
||||
SendFilesPageRequestedEvent(this.jid);
|
||||
final String jid;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user