sendpayload working

This commit is contained in:
Prerak Mann
2019-05-12 00:43:34 +05:30
parent a5a4221188
commit bf1a101c56
3 changed files with 75 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:async';
@@ -35,6 +36,7 @@ class Body extends StatefulWidget {
class _MyBodyState extends State<Body> {
final String userName = Random().nextInt(1000).toString();
final Strategy strategy = Strategy.P2P_STAR;
String cId = "0";
@override
Widget build(BuildContext context) {
@@ -138,6 +140,7 @@ class _MyBodyState extends State<Body> {
RaisedButton(
child: Text("Request Connection"),
onPressed: () {
Navigator.pop(context);
Nearby().requestConnection(
userName,
id,
@@ -160,14 +163,26 @@ class _MyBodyState extends State<Body> {
child:
Text("Accept Connection"),
onPressed: () {
Nearby()
.acceptConnection(id);
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);
},
@@ -215,6 +230,14 @@ class _MyBodyState extends State<Body> {
await Nearby().stopAllEndpoints();
},
),
RaisedButton(
child: Text("Send Random Payload"),
onPressed: () async {
String a = Random().nextInt(100).toString();
showSnackbar("Sending $a");
Nearby().sendPayload(cId, Uint8List.fromList(a.codeUnits));
},
),
],
),
);