chore: Follow up pick files with file selector

pull/1305/merge
Krille 1 year ago
parent 44bd4db774
commit fe06f2efb3
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -508,7 +508,7 @@ class ChatController extends State<ChatPageWithRoom>
final files = await selectFiles(
context,
allowMultiple: true,
extensions: imageExtensions,
type: FileSelectorType.images,
);
if (files.isEmpty) return;

@ -167,7 +167,7 @@ class ChatDetailsController extends State<ChatDetails> {
final picked = await selectFiles(
context,
allowMultiple: false,
extensions: imageExtensions,
type: FileSelectorType.images,
);
final pickedFile = picked.firstOrNull;
if (pickedFile == null) return;

@ -37,7 +37,7 @@ class NewGroupController extends State<NewGroup> {
void selectPhoto() async {
final photo = await selectFiles(
context,
extensions: imageExtensions,
type: FileSelectorType.images,
allowMultiple: false,
);
final bytes = await photo.singleOrNull?.readAsBytes();

@ -34,7 +34,7 @@ class NewSpaceController extends State<NewSpace> {
void selectPhoto() async {
final photo = await selectFiles(
context,
extensions: imageExtensions,
type: FileSelectorType.images,
);
final bytes = await photo.firstOrNull?.readAsBytes();
setState(() {

@ -135,7 +135,10 @@ class SettingsController extends State<Settings> {
name: result.path,
);
} else {
final result = await selectFiles(context, extensions: imageExtensions);
final result = await selectFiles(
context,
type: FileSelectorType.images,
);
final pickedFile = result.firstOrNull;
if (pickedFile == null) return;
file = MatrixFile(

@ -221,7 +221,10 @@ class EmotesSettingsController extends State<EmotesSettings> {
void imagePickerAction(
ValueNotifier<ImagePackImageContent?> controller,
) async {
final result = await selectFiles(context, extensions: imageExtensions);
final result = await selectFiles(
context,
type: FileSelectorType.images,
);
final pickedFile = result.firstOrNull;
if (pickedFile == null) return;
var file = MatrixImageFile(
@ -278,10 +281,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
future: () async {
final result = await selectFiles(
context,
extensions: [
'zip',
// TODO: add further encoders
],
type: FileSelectorType.zip,
);
if (result.isEmpty) return null;

@ -25,7 +25,10 @@ class SettingsStyleController extends State<SettingsStyle> {
void setWallpaper() async {
final client = Matrix.of(context).client;
final picked = await selectFiles(context, extensions: imageExtensions);
final picked = await selectFiles(
context,
type: FileSelectorType.images,
);
final pickedFile = picked.firstOrNull;
if (pickedFile == null) return;

@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/app_lock.dart';
Future<List<XFile>> selectFiles(
BuildContext context, {
String? title,
List<String>? extensions,
FileSelectorType type = FileSelectorType.any,
bool allowMultiple = false,
}) async {
if (!PlatformInfos.isLinux) {
@ -17,7 +17,8 @@ Future<List<XFile>> selectFiles(
FilePicker.platform.pickFiles(
compressionQuality: 0,
allowMultiple: allowMultiple,
allowedExtensions: extensions,
type: type.filePickerType,
allowedExtensions: type.extensions?.toList(),
),
);
return result?.xFiles ?? [];
@ -28,7 +29,8 @@ Future<List<XFile>> selectFiles(
openFiles(
confirmButtonText: title,
acceptedTypeGroups: [
if (extensions != null) XTypeGroup(extensions: extensions),
if (type != FileSelectorType.any)
XTypeGroup(extensions: type.extensions?.toList()),
],
),
);
@ -37,7 +39,8 @@ Future<List<XFile>> selectFiles(
openFile(
confirmButtonText: title,
acceptedTypeGroups: [
if (extensions != null) XTypeGroup(extensions: extensions),
if (type != FileSelectorType.any)
XTypeGroup(extensions: type.extensions?.toList()),
],
),
);
@ -45,13 +48,15 @@ Future<List<XFile>> selectFiles(
return [file];
}
const imageExtensions = [
'png',
'PNG',
'jpg',
'JPG',
'jpeg',
'JPEG',
'webp',
'WebP',
];
enum FileSelectorType {
any(null, FileType.any),
images(
{'png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'webp', 'WebP'},
FileType.image,
),
zip({'zip', 'ZIP'}, FileType.custom);
const FileSelectorType(this.extensions, this.filePickerType);
final Set<String>? extensions;
final FileType filePickerType;
}

Loading…
Cancel
Save