Skip to content

Commit 0dc8a01

Browse files
committed
chore: Follow up save file on desktop
1 parent 8f483c6 commit 0dc8a01

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

lib/utils/matrix_sdk_extensions/matrix_file_extension.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:io';
22

3+
import 'package:file_selector/file_selector.dart';
34
import 'package:flutter/material.dart';
45

56
import 'package:file_picker/file_picker.dart';
6-
import 'package:file_selector/file_selector.dart';
77
import 'package:flutter_gen/gen_l10n/l10n.dart';
88
import 'package:matrix/matrix.dart';
99
import 'package:share_plus/share_plus.dart';
@@ -20,18 +20,27 @@ extension MatrixFileExtension on MatrixFile {
2020
return;
2121
}
2222

23-
final location = await getSaveLocation(
24-
suggestedName: name,
25-
confirmButtonText: L10n.of(context).saveFile,
26-
);
27-
final downloadPath = location?.path;
23+
final downloadPath = !PlatformInfos.isMobile
24+
? (await getSaveLocation(
25+
suggestedName: name,
26+
confirmButtonText: L10n.of(context).saveFile,
27+
))
28+
?.path
29+
: await FilePicker.platform.saveFile(
30+
dialogTitle: L10n.of(context).saveFile,
31+
fileName: name,
32+
type: filePickerFileType,
33+
bytes: bytes,
34+
);
2835
if (downloadPath == null) return;
2936

30-
final result = await showFutureLoadingDialog(
31-
context: context,
32-
future: () => File(downloadPath).writeAsBytes(bytes),
33-
);
34-
if (result.error != null) return;
37+
if (PlatformInfos.isDesktop) {
38+
final result = await showFutureLoadingDialog(
39+
context: context,
40+
future: () => File(downloadPath).writeAsBytes(bytes),
41+
);
42+
if (result.error != null) return;
43+
}
3544

3645
ScaffoldMessenger.of(context).showSnackBar(
3746
SnackBar(

0 commit comments

Comments
 (0)