mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
feat: Share contact as meshcore:// URL via clipboard
This commit is contained in:
@@ -2201,7 +2201,24 @@ class ConnectionProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request fresh device info (triggers SelfInfo response)
|
||||
/// Export a contact as a meshcore:// share URL.
|
||||
/// Pass null to export self.
|
||||
Future<String?> exportContactUrl(Uint8List? publicKey) async {
|
||||
if (!_activeService.isConnected) return null;
|
||||
try {
|
||||
final frame = await _activeService.exportContact(publicKey);
|
||||
final hex = frame
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join();
|
||||
return 'meshcore://$hex';
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ [Provider] exportContact failed: $e');
|
||||
_error = 'Failed to export contact: $e';
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Read custom variables from device (GPS mode, sensor settings, etc.)
|
||||
Future<Map<String, String>> getCustomVars() async {
|
||||
if (!_activeService.isConnected) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
@@ -371,6 +370,35 @@ class ContactTile extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
if (!contact.isChannel)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.share_outlined),
|
||||
title: const Text('Share Contact'),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
final connectionProvider =
|
||||
context.read<ConnectionProvider>();
|
||||
final url = await connectionProvider.exportContactUrl(
|
||||
contact.publicKey,
|
||||
);
|
||||
if (url != null && context.mounted) {
|
||||
await Clipboard.setData(ClipboardData(text: url));
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Contact link copied to clipboard'),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Failed to export contact'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.message_outlined),
|
||||
title: Text(l10n.messages),
|
||||
|
||||
Reference in New Issue
Block a user