Save GPX export via file dialog on desktop
share_plus cannot share files on desktop: the Linux implementation throws
UnimplementedError('Sharing files not supported on Linux') unconditionally
(share_plus_linux.dart:22), and Windows throws for builds older than
10.0.17763. exportGPX() swallowed that in its catch-all, so every GPX
export on Linux ended as gpxExportFailed with the file already written to
the documents directory and never cleaned up.
On desktop, write the file where the user asks via file_selector's
getSaveLocation() instead of routing it through the share sheet; a
dismissed dialog maps to gpxExportCancelled. Mobile keeps the share flow.
Verified on Linux with a standalone probe app: SharePlus.share with files
throws UnimplementedError, while getSaveLocation returns the chosen path
and the GPX file is written there.
This commit is contained in:
3 files changed
+450
-425
No files matched your search
+426
-423
File diff suppressed because it is too large.
Load diff
@@ -7,6 +7,7 @@ import 'dart:io';
|
||||
import '../utils/platform_info.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
|
||||
class ContactExport {
|
||||
final String name;
|
||||
@@ -161,7 +162,6 @@ class GpxExport {
|
||||
final xml = GpxWriter().asString(gpx, pretty: true);
|
||||
|
||||
// 2. Save to file
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final timestamp = DateTime.now()
|
||||
.toUtc()
|
||||
.toIso8601String()
|
||||
@@ -169,8 +169,29 @@ class GpxExport {
|
||||
.replaceAll('.', '-')
|
||||
.split('T')
|
||||
.join('_');
|
||||
final suggestedName = '$filename$timestamp.gpx';
|
||||
|
||||
final path = '${dir.path}/$filename$timestamp.gpx';
|
||||
// share_plus cannot share files on desktop: Linux throws outright
|
||||
// ("Sharing files not supported on Linux") and Windows only supports it
|
||||
// from build 10.0.17763 up. Desktops have a real file system and a save
|
||||
// dialog, so write the file where the user asks instead of sharing it.
|
||||
if (PlatformInfo.isDesktop) {
|
||||
final location = await getSaveLocation(
|
||||
suggestedName: suggestedName,
|
||||
acceptedTypeGroups: const [
|
||||
XTypeGroup(label: 'GPX', extensions: ['gpx']),
|
||||
],
|
||||
);
|
||||
if (location == null) {
|
||||
debugPrint('Save dialog was dismissed / cancelled by user.');
|
||||
return gpxExportCancelled;
|
||||
}
|
||||
await File(location.path).writeAsString(xml);
|
||||
return gpxExportSuccess;
|
||||
}
|
||||
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final path = '${dir.path}/$suggestedName';
|
||||
|
||||
final file = File(path);
|
||||
await file.writeAsString(xml);
|
||||
|
||||
@@ -64,6 +64,7 @@ dependencies:
|
||||
flutter_linkify: ^6.0.0 # Auto-detect and linkify URLs in text
|
||||
gpx: ^2.3.0
|
||||
path_provider: ^2.1.5
|
||||
file_selector: ^1.0.3 # desktop save dialog for GPX export
|
||||
share_plus: ^13.1.0
|
||||
build_pipe: ^0.3.1
|
||||
material_symbols_icons: ^4.2928.1
|
||||
|
||||
Reference in new issue
Block a user