Integrate SharePlus plugin for enhanced sharing functionality across platforms

This commit is contained in:
Winston Lowe
2026-02-08 12:26:49 -08:00
parent bcae6ac19f
commit 2db30ace6a
5 changed files with 80 additions and 36 deletions
+25 -35
View File
@@ -54,50 +54,50 @@ class GpxExport {
} }
void addRepeaters() { void addRepeaters() {
final contacts = _connector.contacts; final contacts = _connector.contacts
final repeaters = contacts
.where((c) => c.type == advTypeRepeater || c.type == advTypeRoom) .where((c) => c.type == advTypeRepeater || c.type == advTypeRoom)
.toList(); .toList();
for (var repeater in repeaters) { for (var contact in contacts) {
if (repeater.latitude == null || repeater.longitude == null) { if (contact.latitude == null || contact.longitude == null) {
continue; continue;
} }
_addContact( _addContact(
repeater.name, contact.name,
repeater.latitude ?? 0.0, contact.latitude!,
repeater.longitude ?? 0.0, contact.longitude!,
"Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}",
); );
} }
} }
void addContacts() { void addContacts() {
final contacts = _connector.contacts; final contacts = _connector.contacts
final repeaters = contacts.where((c) => c.type == advTypeChat).toList(); .where((c) => c.type == advTypeChat)
for (var repeater in repeaters) { .toList();
if (repeater.latitude == null || repeater.longitude == null) { for (var contact in contacts) {
if (contact.latitude == null || contact.longitude == null) {
continue; continue;
} }
_addContact( _addContact(
repeater.name, contact.name,
repeater.latitude ?? 0.0, contact.latitude!,
repeater.longitude ?? 0.0, contact.longitude!,
"Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}",
); );
} }
} }
void addAll() { void addAll() {
final contacts = _connector.contacts; final contacts = _connector.contacts;
for (var repeater in contacts.toList()) { for (var contact in contacts.toList()) {
if (repeater.latitude == null || repeater.longitude == null) { if (contact.latitude == null || contact.longitude == null) {
continue; continue;
} }
_addContact( _addContact(
repeater.name, contact.name,
repeater.latitude ?? 0.0, contact.latitude ?? 0.0,
repeater.longitude ?? 0.0, contact.longitude ?? 0.0,
"Type: ${repeater.typeLabel}\nPublic Key: ${repeater.publicKeyHex}", "Type: ${contact.typeLabel}\nPublic Key: ${contact.publicKeyHex}",
); );
} }
} }
@@ -149,23 +149,17 @@ class GpxExport {
.split('T') .split('T')
.join('_'); .join('_');
// ignore: unnecessary_string_escapes
final path = '${dir.path}/$filename$timestamp.gpx'; final path = '${dir.path}/$filename$timestamp.gpx';
final file = File(path); final file = File(path);
await file.writeAsString(xml); await file.writeAsString(xml);
// 3. Modern share call (2025+ style)
final result = await SharePlus.instance.share( final result = await SharePlus.instance.share(
ShareParams( ShareParams(text: shareText, subject: subject, files: [XFile(path)]),
text: shareText,
subject: subject,
files: [XFile(path)],
// Optional: sharePositionOrigin: ... (if you want iPad popover positioning)
),
); );
// 4. Handle result await file.delete();
switch (result.status) { switch (result.status) {
case ShareResultStatus.success: case ShareResultStatus.success:
debugPrint('Share successful user completed the action.'); debugPrint('Share successful user completed the action.');
@@ -177,12 +171,8 @@ class GpxExport {
debugPrint('Sharing is not available on this platform / context.'); debugPrint('Sharing is not available on this platform / context.');
return gpxExportNotAvailable; return gpxExportNotAvailable;
} }
// Optional cleanup (uncomment if you don't want to keep the file)
// await file.delete();
} catch (e, stack) { } catch (e, stack) {
debugPrint('Export or share failed: $e\n$stack'); debugPrint('Export or share failed: $e\n$stack');
// → here you could show a SnackBar / AlertDialog in real UI code
} }
return gpxExportFailed; return gpxExportFailed;
} }
@@ -9,6 +9,7 @@ import flutter_blue_plus_darwin
import flutter_local_notifications import flutter_local_notifications
import mobile_scanner import mobile_scanner
import package_info_plus import package_info_plus
import share_plus
import shared_preferences_foundation import shared_preferences_foundation
import sqflite_darwin import sqflite_darwin
import url_launcher_macos import url_launcher_macos
@@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin")) MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
+49 -1
View File
@@ -121,6 +121,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.1.2" 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: crypto:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -341,6 +349,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.3" version: "2.1.3"
gpx:
dependency: "direct main"
description:
name: gpx
sha256: f5b12b86402c639079243600ee2b3afd85cd08d26117fc8885cf48efce471d8e
url: "https://pub.dev"
source: hosted
version: "2.3.0"
hooks: hooks:
dependency: transitive dependency: transitive
description: description:
@@ -501,6 +517,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
mime:
dependency: transitive
description:
name: mime
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
mobile_scanner: mobile_scanner:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -566,7 +590,7 @@ packages:
source: hosted source: hosted
version: "1.9.1" version: "1.9.1"
path_provider: path_provider:
dependency: transitive dependency: "direct main"
description: description:
name: path_provider name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
@@ -701,6 +725,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.1.0" version: "4.1.0"
quiver:
dependency: transitive
description:
name: quiver
sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2
url: "https://pub.dev"
source: hosted
version: "3.2.2"
rxdart: rxdart:
dependency: transitive dependency: transitive
description: description:
@@ -709,6 +741,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.28.0" 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: shared_preferences:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -7,11 +7,14 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_blue_plus_winrt/flutter_blue_plus_plugin.h> #include <flutter_blue_plus_winrt/flutter_blue_plus_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterBluePlusPluginRegisterWithRegistrar( FlutterBluePlusPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterBluePlusPlugin")); registry->GetRegistrarForPlugin("FlutterBluePlusPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }
+1
View File
@@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_blue_plus_winrt flutter_blue_plus_winrt
share_plus
url_launcher_windows url_launcher_windows
) )