mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-21 16:21:04 +10:00
add export and import contact frame builders in meshcore_protocol.dart and implement contact export functionality in contacts_screen.dart
This commit is contained in:
@@ -708,3 +708,21 @@ Uint8List buildSendBinaryReq(Uint8List repeaterPubKey, {Uint8List? payload}) {
|
|||||||
}
|
}
|
||||||
return writer.toBytes();
|
return writer.toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build a export contact frame
|
||||||
|
// [cmd][pub_key x32 / if empty exports your contact info]
|
||||||
|
Uint8List buildExportContactFrame(Uint8List pubKey) {
|
||||||
|
final writer = BufferWriter();
|
||||||
|
writer.writeByte(cmdExportContact);
|
||||||
|
writer.writeBytes(pubKey);
|
||||||
|
return writer.toBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a import contact frame
|
||||||
|
// [cmd][contact_frame x148]
|
||||||
|
Uint8List buildImportContactFrame(Uint8List contactFrame) {
|
||||||
|
final writer = BufferWriter();
|
||||||
|
writer.writeByte(cmdImportContact);
|
||||||
|
writer.writeBytes(contactFrame);
|
||||||
|
return writer.toBytes();
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -77,6 +78,13 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
await _groupStore.saveGroups(_groups);
|
await _groupStore.saveGroups(_groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _contactExport(Uint8List pubKey) async {
|
||||||
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
|
final exportContactFrame = buildExportContactFrame(pubKey);
|
||||||
|
await connector.sendFrame(exportContactFrame);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final connector = context.watch<MeshCoreConnector>();
|
final connector = context.watch<MeshCoreConnector>();
|
||||||
@@ -96,18 +104,77 @@ class _ContactsScreenState extends State<ContactsScreen>
|
|||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
PopupMenuButton(itemBuilder: (context) => [
|
||||||
icon: const Icon(Icons.bluetooth_disabled),
|
PopupMenuItem(
|
||||||
tooltip: context.l10n.common_disconnect,
|
child: Row(
|
||||||
onPressed: () => _disconnect(context, connector),
|
children: [
|
||||||
),
|
const Icon(Icons.connect_without_contact),
|
||||||
IconButton(
|
const SizedBox(width: 8),
|
||||||
icon: const Icon(Icons.tune),
|
Text("Zero Hop Advert"),
|
||||||
tooltip: context.l10n.common_settings,
|
],
|
||||||
onPressed: () => Navigator.push(
|
),
|
||||||
context,
|
onTap: () => {
|
||||||
MaterialPageRoute(builder: (context) => const SettingsScreen()),
|
connector.sendSelfAdvert(flood: false),
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text(context.l10n.settings_advertisementSent))),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.cell_tower),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text("Flood Advert"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => {
|
||||||
|
connector.sendSelfAdvert(flood: true),
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text(context.l10n.settings_advertisementSent))),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.copy),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text("Copy Advert to Clipboard"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => _contactExport(Uint8List.fromList([])),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
icon: const Icon(Icons.connect_without_contact),
|
||||||
|
),
|
||||||
|
PopupMenuButton(
|
||||||
|
itemBuilder: (context) => [
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.logout, color: Colors.red),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
const Text('Disconnect'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => _disconnect(context, connector),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.settings),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
const Text('Settings'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => const SettingsScreen()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
icon: const Icon(Icons.more_vert),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user