chore: Combine mimetype types in send file dialog logic
This commit is contained in:
parent
2e40c432a3
commit
1c5580ba62
1 changed files with 13 additions and 14 deletions
|
|
@ -161,8 +161,9 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
var sendStr = L10n.of(context).sendFile;
|
var sendStr = L10n.of(context).sendFile;
|
||||||
final uniqueMimeType = widget.files
|
final uniqueFileType = widget.files
|
||||||
.map((file) => file.mimeType ?? lookupMimeType(file.name))
|
.map((file) => file.mimeType ?? lookupMimeType(file.name))
|
||||||
|
.map((mimeType) => mimeType?.split('/').first)
|
||||||
.toSet()
|
.toSet()
|
||||||
.singleOrNull;
|
.singleOrNull;
|
||||||
|
|
||||||
|
|
@ -175,15 +176,15 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
.join(', ')
|
.join(', ')
|
||||||
.toUpperCase();
|
.toUpperCase();
|
||||||
|
|
||||||
if (uniqueMimeType?.startsWith('image') ?? false) {
|
if (uniqueFileType == 'image') {
|
||||||
if (widget.files.length == 1) {
|
if (widget.files.length == 1) {
|
||||||
sendStr = L10n.of(context).sendImage;
|
sendStr = L10n.of(context).sendImage;
|
||||||
} else {
|
} else {
|
||||||
sendStr = L10n.of(context).sendImages(widget.files.length);
|
sendStr = L10n.of(context).sendImages(widget.files.length);
|
||||||
}
|
}
|
||||||
} else if (uniqueMimeType?.startsWith('audio') ?? false) {
|
} else if (uniqueFileType == 'audio') {
|
||||||
sendStr = L10n.of(context).sendAudio;
|
sendStr = L10n.of(context).sendAudio;
|
||||||
} else if (uniqueMimeType?.startsWith('video') ?? false) {
|
} else if (uniqueFileType == 'video') {
|
||||||
sendStr = L10n.of(context).sendVideo;
|
sendStr = L10n.of(context).sendVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +202,7 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
if (uniqueMimeType?.startsWith('image') ?? false)
|
if (uniqueFileType == 'image')
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 16.0),
|
padding: const EdgeInsets.only(bottom: 16.0),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
|
|
@ -233,17 +234,17 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (uniqueMimeType?.startsWith('image') != true)
|
if (uniqueFileType != 'image')
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 16.0),
|
padding: const EdgeInsets.only(bottom: 16.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
uniqueMimeType == null
|
uniqueFileType == null
|
||||||
? Icons.description_outlined
|
? Icons.description_outlined
|
||||||
: uniqueMimeType.startsWith('video')
|
: uniqueFileType == 'video'
|
||||||
? Icons.video_file_outlined
|
? Icons.video_file_outlined
|
||||||
: uniqueMimeType.startsWith('audio')
|
: uniqueFileType == 'audio'
|
||||||
? Icons.audio_file_outlined
|
? Icons.audio_file_outlined
|
||||||
: Icons.description_outlined,
|
: Icons.description_outlined,
|
||||||
size: 32,
|
size: 32,
|
||||||
|
|
@ -272,9 +273,7 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Workaround for SwitchListTile.adaptive crashes in CupertinoDialog
|
// Workaround for SwitchListTile.adaptive crashes in CupertinoDialog
|
||||||
if (uniqueMimeType != null &&
|
if ({'image', 'video'}.contains(uniqueFileType))
|
||||||
(uniqueMimeType.startsWith('image') ||
|
|
||||||
uniqueMimeType.startsWith('video')))
|
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -282,7 +281,7 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
.contains(theme.platform))
|
.contains(theme.platform))
|
||||||
CupertinoSwitch(
|
CupertinoSwitch(
|
||||||
value: compress,
|
value: compress,
|
||||||
onChanged: uniqueMimeType.startsWith('video') &&
|
onChanged: uniqueFileType == 'video' &&
|
||||||
!PlatformInfos.isMobile
|
!PlatformInfos.isMobile
|
||||||
? null
|
? null
|
||||||
: (v) => setState(() => compress = v),
|
: (v) => setState(() => compress = v),
|
||||||
|
|
@ -290,7 +289,7 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
else
|
else
|
||||||
Switch.adaptive(
|
Switch.adaptive(
|
||||||
value: compress,
|
value: compress,
|
||||||
onChanged: uniqueMimeType.startsWith('video') &&
|
onChanged: uniqueFileType == 'video' &&
|
||||||
!PlatformInfos.isMobile
|
!PlatformInfos.isMobile
|
||||||
? null
|
? null
|
||||||
: (v) => setState(() => compress = v),
|
: (v) => setState(() => compress = v),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue