mirror of
https://github.com/hackku21/loc-chain-app.git
synced 2024-10-27 20:34:05 +00:00
update bluetooth
This commit is contained in:
parent
dceeb18513
commit
13eeafabaa
@ -8,29 +8,44 @@ import 'package:nearby_connections/nearby_connections.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class Connect {
|
class Connect {
|
||||||
|
final serviceId = "com.yourdomain.appname";
|
||||||
|
final Strategy strategy = Strategy.P2P_STAR;
|
||||||
|
late final _userName;
|
||||||
|
|
||||||
|
Map<String, ConnectionInfo> endpointMap = Map();
|
||||||
|
|
||||||
|
Connect() {
|
||||||
|
SharedPreferences.getInstance()
|
||||||
|
.then((s) => _userName = s.getString('userName') ?? '0');
|
||||||
|
}
|
||||||
|
|
||||||
void startConnect() async {
|
void startConnect() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
// final prefs = await SharedPreferences.getInstance();
|
||||||
final userName = prefs.getString('userName') ?? " ";
|
// final userName = prefs.getString('userName') ?? " ";
|
||||||
final Strategy strategy = Strategy.P2P_STAR;
|
|
||||||
final serviceId = "com.yourdomain.appname";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bool advertise = await Nearby().startAdvertising(
|
bool advertise = await Nearby().startAdvertising(
|
||||||
userName,
|
_userName,
|
||||||
strategy,
|
strategy,
|
||||||
onConnectionInitiated: (String id, ConnectionInfo info) {
|
onConnectionInitiated: (String id, ConnectionInfo info) {
|
||||||
// Called whenever a discoverer requests connection
|
// Called whenever a discoverer requests connection
|
||||||
|
//
|
||||||
|
// onConnectionInit
|
||||||
},
|
},
|
||||||
onConnectionResult: (String id, Status status) {
|
onConnectionResult: (String id, Status status) {
|
||||||
// Called when connection is accepted/rejected
|
// Called when connection is accepted/rejected
|
||||||
|
// if connection is accepted send the transaction
|
||||||
|
//
|
||||||
|
//
|
||||||
},
|
},
|
||||||
onDisconnected: (String id) {
|
onDisconnected: (String id) {
|
||||||
// Callled whenever a discoverer disconnects from advertiser
|
// Callled whenever a discoverer disconnects from advertiser
|
||||||
},
|
},
|
||||||
serviceId: serviceId, // uniquely identifies your app
|
serviceId: serviceId, // uniquely identifies your app
|
||||||
);
|
);
|
||||||
|
|
||||||
bool discovery = await Nearby().startDiscovery(
|
bool discovery = await Nearby().startDiscovery(
|
||||||
userName,
|
_userName,
|
||||||
strategy,
|
strategy,
|
||||||
onEndpointFound: (String id, String userName, String serviceId) {
|
onEndpointFound: (String id, String userName, String serviceId) {
|
||||||
// called when an advertiser is found
|
// called when an advertiser is found
|
||||||
|
Loading…
Reference in New Issue
Block a user