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( final files = await selectFiles(
context, context,
allowMultiple: true, allowMultiple: true,
extensions: imageExtensions, type: FileSelectorType.images,
); );
if (files.isEmpty) return; if (files.isEmpty) return;

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

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

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

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

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

@ -25,7 +25,10 @@ class SettingsStyleController extends State<SettingsStyle> {
void setWallpaper() async { void setWallpaper() async {
final client = Matrix.of(context).client; 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; final pickedFile = picked.firstOrNull;
if (pickedFile == null) return; if (pickedFile == null) return;

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

Loading…
Cancel
Save