chore: Merge upstream changes --------- Signed-off-by: Krille <c.kussowski@famedly.com> Co-authored-by: krille-chan <christian-kussowski@posteo.de> Co-authored-by: Krille <c.kussowski@famedly.com> Co-authored-by: Linerly <linerly@proton.me> Co-authored-by: Priit Jõerüüt <hwlate@joeruut.com> Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org> Co-authored-by: fadelkon <fadelkon@posteo.net> Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com> Co-authored-by: Edgars Andersons <Edgars+Weblate@gaitenis.id.lv> Co-authored-by: josé m <correoxm@disroot.org> Co-authored-by: Bezruchenko Simon <worcposj44@gmail.com> Co-authored-by: Christian <christian-pauly@posteo.de> Co-authored-by: - <hitekex@yandex.ru> Co-authored-by: Angelo Schirinzi <Odi-3@users.noreply.hosted.weblate.org> Co-authored-by: xabirequejo <xabi.rn@gmail.com> Co-authored-by: Piotr Orzechowski <piotr@orzechowski.tech> Co-authored-by: Rex_sa <rex.sa@pm.me> Co-authored-by: Tewuzij <tenajeza@outlook.com> Co-authored-by: goknarbahceli <goknarbahceli@proton.me> Co-authored-by: தமிழ்நேரம் <anishprabu.t@gmail.com> Co-authored-by: Erin <erin@erindesu.cz> Co-authored-by: EpicKiwi <me@epickiwi.fr> Co-authored-by: Christian Tietze <me@christiantietze.de> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
84 lines
2 KiB
Dart
84 lines
2 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:file_selector/file_selector.dart';
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
import 'package:fluffychat/widgets/app_lock.dart';
|
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
|
|
|
Future<List<XFile>> selectFiles(
|
|
BuildContext context, {
|
|
String? title,
|
|
FileSelectorType type = FileSelectorType.any,
|
|
bool allowMultiple = false,
|
|
}) async {
|
|
if (!PlatformInfos.isLinux) {
|
|
final result = await AppLock.of(context).pauseWhile(
|
|
showFutureLoadingDialog(
|
|
context: context,
|
|
future: () => FilePicker.platform.pickFiles(
|
|
compressionQuality: 0,
|
|
allowMultiple: allowMultiple,
|
|
type: type.filePickerType,
|
|
allowedExtensions: type.extensions,
|
|
),
|
|
),
|
|
);
|
|
return result.result?.xFiles ?? [];
|
|
}
|
|
|
|
if (allowMultiple) {
|
|
return await AppLock.of(context).pauseWhile(
|
|
openFiles(
|
|
confirmButtonText: title,
|
|
acceptedTypeGroups: type.groups,
|
|
),
|
|
);
|
|
}
|
|
final file = await AppLock.of(context).pauseWhile(
|
|
openFile(
|
|
confirmButtonText: title,
|
|
acceptedTypeGroups: type.groups,
|
|
),
|
|
);
|
|
if (file == null) return [];
|
|
return [file];
|
|
}
|
|
|
|
enum FileSelectorType {
|
|
any([], FileType.any, null),
|
|
images(
|
|
[
|
|
XTypeGroup(
|
|
label: 'JPG',
|
|
extensions: <String>['jpg', 'JPG', 'jpeg', 'JPEG'],
|
|
),
|
|
XTypeGroup(
|
|
label: 'PNGs',
|
|
extensions: <String>['png', 'PNG'],
|
|
),
|
|
XTypeGroup(
|
|
label: 'WEBP',
|
|
extensions: <String>['WebP', 'WEBP'],
|
|
),
|
|
],
|
|
FileType.image,
|
|
null,
|
|
),
|
|
zip(
|
|
[
|
|
XTypeGroup(
|
|
label: 'ZIP',
|
|
extensions: <String>['zip', 'ZIP'],
|
|
),
|
|
],
|
|
FileType.custom,
|
|
['zip', 'ZIP'],
|
|
);
|
|
|
|
const FileSelectorType(this.groups, this.filePickerType, this.extensions);
|
|
final List<XTypeGroup> groups;
|
|
final FileType filePickerType;
|
|
final List<String>? extensions;
|
|
}
|