mirror of
https://github.com/hackku21/nearby_connections.git
synced 2024-10-27 19:14:01 +00:00
example working
This commit is contained in:
parent
bf1a101c56
commit
c118ce5096
@ -216,8 +216,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
assert endpointId != null;
|
||||
assert bytes != null;
|
||||
String hello = "okay";
|
||||
Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(hello.getBytes()));
|
||||
Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(bytes));
|
||||
Log.d("NearbyCon java", "sentPayload");
|
||||
|
||||
break;
|
||||
|
@ -40,7 +40,6 @@ class _MyBodyState extends State<Body> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// TODO: implement build
|
||||
return Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
@ -71,34 +70,7 @@ class _MyBodyState extends State<Body> {
|
||||
userName,
|
||||
strategy,
|
||||
onConnectionInitiated: (id, info) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text("id: " + id),
|
||||
Text("Token: " + info.authenticationToken),
|
||||
Text("Name" + info.endpointName),
|
||||
Text("Incoming: " +
|
||||
info.isIncomingConnection.toString()),
|
||||
RaisedButton(
|
||||
child: Text("Accept Connection"),
|
||||
onPressed: () {
|
||||
Nearby().acceptConnection(id);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Reject Connection"),
|
||||
onPressed: () {
|
||||
Nearby().rejectConnection(id);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
oci(id, info);
|
||||
},
|
||||
onConnectionResult: (id, status) {
|
||||
showSnackbar(status);
|
||||
@ -145,53 +117,7 @@ class _MyBodyState extends State<Body> {
|
||||
userName,
|
||||
id,
|
||||
onConnectionInitiated: (id, info) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text("id: " + id),
|
||||
Text("Token: " +
|
||||
info.authenticationToken),
|
||||
Text(
|
||||
"Name" + info.endpointName),
|
||||
Text("Incoming: " +
|
||||
info.isIncomingConnection
|
||||
.toString()),
|
||||
RaisedButton(
|
||||
child:
|
||||
Text("Accept Connection"),
|
||||
onPressed: () {
|
||||
cId = id;
|
||||
Nearby().acceptConnection(
|
||||
id,
|
||||
onPayLoadRecieved:
|
||||
(id, bytes) {
|
||||
showSnackbar(id +
|
||||
": " +
|
||||
String
|
||||
.fromCharCodes(
|
||||
bytes));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child:
|
||||
Text("Reject Connection"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
|
||||
Nearby()
|
||||
.rejectConnection(id);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
oci(id, info);
|
||||
},
|
||||
onConnectionResult: (id, status) {
|
||||
showSnackbar(status);
|
||||
@ -234,7 +160,7 @@ class _MyBodyState extends State<Body> {
|
||||
child: Text("Send Random Payload"),
|
||||
onPressed: () async {
|
||||
String a = Random().nextInt(100).toString();
|
||||
showSnackbar("Sending $a");
|
||||
showSnackbar("Sending $a to $cId");
|
||||
Nearby().sendPayload(cId, Uint8List.fromList(a.codeUnits));
|
||||
},
|
||||
),
|
||||
@ -248,4 +174,43 @@ class _MyBodyState extends State<Body> {
|
||||
content: Text(a.toString()),
|
||||
));
|
||||
}
|
||||
|
||||
void oci(String id, ConnectionInfo info) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text("id: " + id),
|
||||
Text("Token: " + info.authenticationToken),
|
||||
Text("Name" + info.endpointName),
|
||||
Text("Incoming: " + info.isIncomingConnection.toString()),
|
||||
RaisedButton(
|
||||
child: Text("Accept Connection"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
cId = id;
|
||||
Nearby().acceptConnection(
|
||||
id,
|
||||
onPayLoadRecieved: (endid, bytes) {
|
||||
showSnackbar(endid + ": " + String.fromCharCodes(bytes));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Reject Connection"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
|
||||
Nearby().rejectConnection(id);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user