example working

This commit is contained in:
Prerak Mann 2019-05-12 01:07:58 +05:30
parent bf1a101c56
commit c118ce5096
2 changed files with 43 additions and 79 deletions

View File

@ -216,8 +216,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
assert endpointId != null; assert endpointId != null;
assert bytes != null; assert bytes != null;
String hello = "okay"; Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(bytes));
Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(hello.getBytes()));
Log.d("NearbyCon java", "sentPayload"); Log.d("NearbyCon java", "sentPayload");
break; break;

View File

@ -40,7 +40,6 @@ class _MyBodyState extends State<Body> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO: implement build
return Center( return Center(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
@ -71,34 +70,7 @@ class _MyBodyState extends State<Body> {
userName, userName,
strategy, strategy,
onConnectionInitiated: (id, info) { onConnectionInitiated: (id, info) {
showModalBottomSheet( oci(id, info);
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);
},
),
],
),
);
},
);
}, },
onConnectionResult: (id, status) { onConnectionResult: (id, status) {
showSnackbar(status); showSnackbar(status);
@ -145,53 +117,7 @@ class _MyBodyState extends State<Body> {
userName, userName,
id, id,
onConnectionInitiated: (id, info) { onConnectionInitiated: (id, info) {
showModalBottomSheet( oci(id, info);
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);
},
),
],
),
);
},
);
}, },
onConnectionResult: (id, status) { onConnectionResult: (id, status) {
showSnackbar(status); showSnackbar(status);
@ -234,7 +160,7 @@ class _MyBodyState extends State<Body> {
child: Text("Send Random Payload"), child: Text("Send Random Payload"),
onPressed: () async { onPressed: () async {
String a = Random().nextInt(100).toString(); String a = Random().nextInt(100).toString();
showSnackbar("Sending $a"); showSnackbar("Sending $a to $cId");
Nearby().sendPayload(cId, Uint8List.fromList(a.codeUnits)); Nearby().sendPayload(cId, Uint8List.fromList(a.codeUnits));
}, },
), ),
@ -248,4 +174,43 @@ class _MyBodyState extends State<Body> {
content: Text(a.toString()), 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);
},
),
],
),
);
},
);
}
} }