Skip to content

Commit

Permalink
chore: Follow up save file on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 29, 2024
1 parent 8f483c6 commit 0dc8a01
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/utils/matrix_sdk_extensions/matrix_file_extension.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';

import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';

import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:share_plus/share_plus.dart';
Expand All @@ -20,18 +20,27 @@ extension MatrixFileExtension on MatrixFile {
return;
}

final location = await getSaveLocation(
suggestedName: name,
confirmButtonText: L10n.of(context).saveFile,
);
final downloadPath = location?.path;
final downloadPath = !PlatformInfos.isMobile
? (await getSaveLocation(
suggestedName: name,
confirmButtonText: L10n.of(context).saveFile,
))
?.path
: await FilePicker.platform.saveFile(
dialogTitle: L10n.of(context).saveFile,
fileName: name,
type: filePickerFileType,
bytes: bytes,
);
if (downloadPath == null) return;

final result = await showFutureLoadingDialog(
context: context,
future: () => File(downloadPath).writeAsBytes(bytes),
);
if (result.error != null) return;
if (PlatformInfos.isDesktop) {
final result = await showFutureLoadingDialog(
context: context,
future: () => File(downloadPath).writeAsBytes(bytes),
);
if (result.error != null) return;
}

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down

0 comments on commit 0dc8a01

Please sign in to comment.