chore: Follow up save file on desktop
This commit is contained in:
parent
8f483c64c0
commit
0dc8a015d3
1 changed files with 20 additions and 11 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:file_selector/file_selector.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.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:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
@ -20,18 +20,27 @@ extension MatrixFileExtension on MatrixFile {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final location = await getSaveLocation(
|
final downloadPath = !PlatformInfos.isMobile
|
||||||
suggestedName: name,
|
? (await getSaveLocation(
|
||||||
confirmButtonText: L10n.of(context).saveFile,
|
suggestedName: name,
|
||||||
);
|
confirmButtonText: L10n.of(context).saveFile,
|
||||||
final downloadPath = location?.path;
|
))
|
||||||
|
?.path
|
||||||
|
: await FilePicker.platform.saveFile(
|
||||||
|
dialogTitle: L10n.of(context).saveFile,
|
||||||
|
fileName: name,
|
||||||
|
type: filePickerFileType,
|
||||||
|
bytes: bytes,
|
||||||
|
);
|
||||||
if (downloadPath == null) return;
|
if (downloadPath == null) return;
|
||||||
|
|
||||||
final result = await showFutureLoadingDialog(
|
if (PlatformInfos.isDesktop) {
|
||||||
context: context,
|
final result = await showFutureLoadingDialog(
|
||||||
future: () => File(downloadPath).writeAsBytes(bytes),
|
context: context,
|
||||||
);
|
future: () => File(downloadPath).writeAsBytes(bytes),
|
||||||
if (result.error != null) return;
|
);
|
||||||
|
if (result.error != null) return;
|
||||||
|
}
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue