From 2db30ace6a1e3f7937fd562697ca5961810dddcd Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Sun, 8 Feb 2026 12:26:49 -0800 Subject: [PATCH] Integrate SharePlus plugin for enhanced sharing functionality across platforms --- lib/utils/gpx_export.dart | 60 ++++++++----------- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 50 +++++++++++++++- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 5 files changed, 80 insertions(+), 36 deletions(-) diff --git a/lib/utils/gpx_export.dart b/lib/utils/gpx_export.dart index 92494c9..595479c 100644 --- a/lib/utils/gpx_export.dart +++ b/lib/utils/gpx_export.dart @@ -54,50 +54,50 @@ class GpxExport { } void addRepeaters() { - final contacts = _connector.contacts; - final repeaters = contacts + final contacts = _connector.contacts .where((c) => c.type == advTypeRepeater || c.type == advTypeRoom) .toList(); - for (var repeater in repeaters) { - if (repeater.latitude == null || repeater.longitude == null) { + for (var contact in contacts) { + if (contact.latitude == null || contact.longitude == null) { continue; } _addContact( - repeater.name, - repeater.latitude ?? 0.0, - repeater.longitude ?? 0.0, - "Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", + contact.name, + contact.latitude!, + contact.longitude!, + "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}", ); } } void addContacts() { - final contacts = _connector.contacts; - final repeaters = contacts.where((c) => c.type == advTypeChat).toList(); - for (var repeater in repeaters) { - if (repeater.latitude == null || repeater.longitude == null) { + final contacts = _connector.contacts + .where((c) => c.type == advTypeChat) + .toList(); + for (var contact in contacts) { + if (contact.latitude == null || contact.longitude == null) { continue; } _addContact( - repeater.name, - repeater.latitude ?? 0.0, - repeater.longitude ?? 0.0, - "Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", + contact.name, + contact.latitude!, + contact.longitude!, + "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}", ); } } void addAll() { final contacts = _connector.contacts; - for (var repeater in contacts.toList()) { - if (repeater.latitude == null || repeater.longitude == null) { + for (var contact in contacts.toList()) { + if (contact.latitude == null || contact.longitude == null) { continue; } _addContact( - repeater.name, - repeater.latitude ?? 0.0, - repeater.longitude ?? 0.0, - "Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", + contact.name, + contact.latitude ?? 0.0, + contact.longitude ?? 0.0, + "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}", ); } } @@ -149,23 +149,17 @@ class GpxExport { .split('T') .join('_'); - // ignore: unnecessary_string_escapes final path = '${dir.path}/$filename$timestamp.gpx'; final file = File(path); await file.writeAsString(xml); - // 3. Modern share call (2025+ style) final result = await SharePlus.instance.share( - ShareParams( - text: shareText, - subject: subject, - files: [XFile(path)], - // Optional: sharePositionOrigin: ... (if you want iPad popover positioning) - ), + ShareParams(text: shareText, subject: subject, files: [XFile(path)]), ); - // 4. Handle result + await file.delete(); + switch (result.status) { case ShareResultStatus.success: debugPrint('Share successful – user completed the action.'); @@ -177,12 +171,8 @@ class GpxExport { debugPrint('Sharing is not available on this platform / context.'); return gpxExportNotAvailable; } - - // Optional cleanup (uncomment if you don't want to keep the file) - // await file.delete(); } catch (e, stack) { debugPrint('Export or share failed: $e\n$stack'); - // → here you could show a SnackBar / AlertDialog in real UI code } return gpxExportFailed; } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index b4a41dd..d2ea57e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -9,6 +9,7 @@ import flutter_blue_plus_darwin import flutter_local_notifications import mobile_scanner import package_info_plus +import share_plus import shared_preferences_foundation import sqflite_darwin import url_launcher_macos @@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) + SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 1e275d4..fc11656 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -121,6 +121,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.2" + cross_file: + dependency: transitive + description: + name: cross_file + sha256: "28bb3ae56f117b5aec029d702a90f57d285cd975c3c5c281eaca38dbc47c5937" + url: "https://pub.dev" + source: hosted + version: "0.3.5+2" crypto: dependency: "direct main" description: @@ -341,6 +349,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" + gpx: + dependency: "direct main" + description: + name: gpx + sha256: f5b12b86402c639079243600ee2b3afd85cd08d26117fc8885cf48efce471d8e + url: "https://pub.dev" + source: hosted + version: "2.3.0" hooks: dependency: transitive description: @@ -501,6 +517,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + mime: + dependency: transitive + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" mobile_scanner: dependency: "direct main" description: @@ -566,7 +590,7 @@ packages: source: hosted version: "1.9.1" path_provider: - dependency: transitive + dependency: "direct main" description: name: path_provider sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" @@ -701,6 +725,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + quiver: + dependency: transitive + description: + name: quiver + sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2 + url: "https://pub.dev" + source: hosted + version: "3.2.2" rxdart: dependency: transitive description: @@ -709,6 +741,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.28.0" + share_plus: + dependency: "direct main" + description: + name: share_plus + sha256: "14c8860d4de93d3a7e53af51bff479598c4e999605290756bbbe45cf65b37840" + url: "https://pub.dev" + source: hosted + version: "12.0.1" + share_plus_platform_interface: + dependency: transitive + description: + name: share_plus_platform_interface + sha256: "88023e53a13429bd65d8e85e11a9b484f49d4c190abbd96c7932b74d6927cc9a" + url: "https://pub.dev" + source: hosted + version: "6.1.0" shared_preferences: dependency: "direct main" description: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index eeb548f..cd4fc19 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,11 +7,14 @@ #include "generated_plugin_registrant.h" #include +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { FlutterBluePlusPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterBluePlusPlugin")); + SharePlusWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 68825d8..571addb 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST flutter_blue_plus_winrt + share_plus url_launcher_windows )