refactor: File selector just use default FileType
and remove not working zip selector
This commit is contained in:
parent
803602e3c5
commit
53af09227f
7 changed files with 18 additions and 116 deletions
|
|
@ -9,6 +9,7 @@ import 'package:collection/collection.dart';
|
|||
import 'package:desktop_drop/desktop_drop.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -621,7 +622,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
});
|
||||
}
|
||||
|
||||
void sendFileAction({FileSelectorType type = FileSelectorType.any}) async {
|
||||
void sendFileAction({FileType type = FileType.any}) async {
|
||||
final files = await selectFiles(context, allowMultiple: true, type: type);
|
||||
if (files.isEmpty) return;
|
||||
await showAdaptiveDialog(
|
||||
|
|
@ -1186,10 +1187,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
switch (choice) {
|
||||
case AddPopupMenuActions.image:
|
||||
sendFileAction(type: FileSelectorType.images);
|
||||
sendFileAction(type: FileType.image);
|
||||
return;
|
||||
case AddPopupMenuActions.video:
|
||||
sendFileAction(type: FileSelectorType.videos);
|
||||
sendFileAction(type: FileType.video);
|
||||
return;
|
||||
case AddPopupMenuActions.file:
|
||||
sendFileAction();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -137,7 +138,7 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||
final picked = await selectFiles(
|
||||
context,
|
||||
allowMultiple: false,
|
||||
type: FileSelectorType.images,
|
||||
type: FileType.image,
|
||||
);
|
||||
final pickedFile = picked.firstOrNull;
|
||||
if (pickedFile == null) return;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:typed_data';
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart' as sdk;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -49,7 +50,7 @@ class NewGroupController extends State<NewGroup> {
|
|||
void selectPhoto() async {
|
||||
final photo = await selectFiles(
|
||||
context,
|
||||
type: FileSelectorType.images,
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
);
|
||||
final bytes = await photo.singleOrNull?.readAsBytes();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
|
@ -134,7 +135,7 @@ class SettingsController extends State<Settings> {
|
|||
if (result == null) return;
|
||||
file = MatrixFile(bytes: await result.readAsBytes(), name: result.path);
|
||||
} else {
|
||||
final result = await selectFiles(context, type: FileSelectorType.images);
|
||||
final result = await selectFiles(context, type: FileType.image);
|
||||
final pickedFile = result.firstOrNull;
|
||||
if (pickedFile == null) return;
|
||||
file = MatrixFile(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:http/http.dart' hide Client;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -296,7 +297,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
void createStickers() async {
|
||||
final pickedFiles = await selectFiles(
|
||||
context,
|
||||
type: FileSelectorType.images,
|
||||
type: FileType.image,
|
||||
allowMultiple: true,
|
||||
);
|
||||
if (pickedFiles.isEmpty) return;
|
||||
|
|
@ -355,7 +356,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
}
|
||||
|
||||
Future<void> importEmojiZip() async {
|
||||
final result = await selectFiles(context, type: FileSelectorType.zip);
|
||||
final result = await selectFiles(context, type: FileType.any);
|
||||
|
||||
if (result.isEmpty) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
|
|
@ -26,7 +28,7 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
|
||||
void setWallpaper() async {
|
||||
final client = Matrix.of(context).client;
|
||||
final picked = await selectFiles(context, type: FileSelectorType.images);
|
||||
final picked = await selectFiles(context, type: FileType.image);
|
||||
final pickedFile = picked.firstOrNull;
|
||||
if (pickedFile == null) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
|||
Future<List<XFile>> selectFiles(
|
||||
BuildContext context, {
|
||||
String? title,
|
||||
FileSelectorType type = FileSelectorType.any,
|
||||
FileType type = FileType.any,
|
||||
bool allowMultiple = false,
|
||||
}) async {
|
||||
final result = await AppLock.of(context).pauseWhile(
|
||||
|
|
@ -18,114 +18,9 @@ Future<List<XFile>> selectFiles(
|
|||
future: () => FilePicker.platform.pickFiles(
|
||||
compressionQuality: 0,
|
||||
allowMultiple: allowMultiple,
|
||||
type: type.filePickerType,
|
||||
allowedExtensions: type.extensions,
|
||||
type: type,
|
||||
),
|
||||
),
|
||||
);
|
||||
return result.result?.xFiles ?? [];
|
||||
}
|
||||
|
||||
enum FileSelectorType {
|
||||
any([], FileType.any, null),
|
||||
images(
|
||||
[
|
||||
XTypeGroup(
|
||||
label: 'Images',
|
||||
extensions: <String>[
|
||||
'jpg',
|
||||
'JPG',
|
||||
'jpeg',
|
||||
'JPEG',
|
||||
'png',
|
||||
'PNG',
|
||||
'webp',
|
||||
'WebP',
|
||||
'WEBP',
|
||||
'gif',
|
||||
'GIF',
|
||||
'bmp',
|
||||
'BMP',
|
||||
'tiff',
|
||||
'TIFF',
|
||||
'tif',
|
||||
'TIF',
|
||||
'heic',
|
||||
'HEIC',
|
||||
'svg',
|
||||
'SVG',
|
||||
],
|
||||
),
|
||||
XTypeGroup(
|
||||
label: 'JPG',
|
||||
extensions: <String>['jpg', 'JPG', 'jpeg', 'JPEG'],
|
||||
),
|
||||
XTypeGroup(label: 'PNG', extensions: <String>['png', 'PNG']),
|
||||
XTypeGroup(label: 'WebP', extensions: <String>['webp', 'WebP', 'WEBP']),
|
||||
XTypeGroup(label: 'GIF', extensions: <String>['gif', 'GIF']),
|
||||
XTypeGroup(label: 'BMP', extensions: <String>['bmp', 'BMP']),
|
||||
XTypeGroup(
|
||||
label: 'TIFF',
|
||||
extensions: <String>['tiff', 'TIFF', 'tif', 'TIF'],
|
||||
),
|
||||
XTypeGroup(label: 'HEIC', extensions: <String>['heic', 'HEIC']),
|
||||
XTypeGroup(label: 'SVG', extensions: <String>['svg', 'SVG']),
|
||||
],
|
||||
FileType.image,
|
||||
null,
|
||||
),
|
||||
videos(
|
||||
[
|
||||
XTypeGroup(
|
||||
label: 'Videos',
|
||||
extensions: <String>[
|
||||
'mp4',
|
||||
'MP4',
|
||||
'avi',
|
||||
'AVI',
|
||||
'webm',
|
||||
'WebM',
|
||||
'WEBM',
|
||||
'mov',
|
||||
'MOV',
|
||||
'mkv',
|
||||
'MKV',
|
||||
'wmv',
|
||||
'WMV',
|
||||
'flv',
|
||||
'FLV',
|
||||
'mpeg',
|
||||
'MPEG',
|
||||
'3gp',
|
||||
'3GP',
|
||||
'ogg',
|
||||
'OGG',
|
||||
],
|
||||
),
|
||||
XTypeGroup(label: 'MP4', extensions: <String>['mp4', 'MP4']),
|
||||
XTypeGroup(label: 'WebM', extensions: <String>['webm', 'WebM', 'WEBM']),
|
||||
XTypeGroup(label: 'AVI', extensions: <String>['avi', 'AVI']),
|
||||
XTypeGroup(label: 'MOV', extensions: <String>['mov', 'MOV']),
|
||||
XTypeGroup(label: 'MKV', extensions: <String>['mkv', 'MKV']),
|
||||
XTypeGroup(label: 'WMV', extensions: <String>['wmv', 'WMV']),
|
||||
XTypeGroup(label: 'FLV', extensions: <String>['flv', 'FLV']),
|
||||
XTypeGroup(label: 'MPEG', extensions: <String>['mpeg', 'MPEG']),
|
||||
XTypeGroup(label: '3GP', extensions: <String>['3gp', '3GP']),
|
||||
XTypeGroup(label: 'OGG', extensions: <String>['ogg', 'OGG']),
|
||||
],
|
||||
FileType.video,
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue