mirror of
https://github.com/hackku21/nearby_connections.git
synced 2024-10-27 19:14:01 +00:00
Merge the null_safety with master. (#27)
* initial migration using tool * minor changes * Completed null safety migration * updated changelog * Fix typo in PayloadStatus enum. * Format changes * Minor changes
This commit is contained in:
parent
c2adf90962
commit
0797dedc35
@ -1,3 +1,9 @@
|
|||||||
|
## 3.0.0-nullsafety.1
|
||||||
|
* Fix typo in PayloadStatus enum (`IN_PROGRRESS -> IN_PROGRESS`).
|
||||||
|
|
||||||
|
## 3.0.0-nullsafety.0
|
||||||
|
* Migrated to Null Safety.
|
||||||
|
|
||||||
## 2.0.2
|
## 2.0.2
|
||||||
* Fix missingPluginException.
|
* Fix missingPluginException.
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class _MyBodyState extends State<Body> {
|
|||||||
|
|
||||||
File tempFile; //reference to the file currently being transferred
|
File tempFile; //reference to the file currently being transferred
|
||||||
Map<int, String> map =
|
Map<int, String> map =
|
||||||
Map(); //store filename mapped to corresponding payloadId
|
Map(); //store filename mapped to corresponding payloadId
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -57,12 +57,12 @@ class _MyBodyState extends State<Body> {
|
|||||||
child: Text("checkLocationPermission"),
|
child: Text("checkLocationPermission"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await Nearby().checkLocationPermission()) {
|
if (await Nearby().checkLocationPermission()) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text("Location permissions granted :)")));
|
content: Text("Location permissions granted :)")));
|
||||||
} else {
|
} else {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content:
|
content:
|
||||||
Text("Location permissions not granted :(")));
|
Text("Location permissions not granted :(")));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -70,12 +70,12 @@ class _MyBodyState extends State<Body> {
|
|||||||
child: Text("askLocationPermission"),
|
child: Text("askLocationPermission"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await Nearby().askLocationPermission()) {
|
if (await Nearby().askLocationPermission()) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text("Location Permission granted :)")));
|
content: Text("Location Permission granted :)")));
|
||||||
} else {
|
} else {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content:
|
content:
|
||||||
Text("Location permissions not granted :(")));
|
Text("Location permissions not granted :(")));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -83,11 +83,11 @@ class _MyBodyState extends State<Body> {
|
|||||||
child: Text("checkExternalStoragePermission"),
|
child: Text("checkExternalStoragePermission"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await Nearby().checkExternalStoragePermission()) {
|
if (await Nearby().checkExternalStoragePermission()) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content:
|
content:
|
||||||
Text("External Storage permissions granted :)")));
|
Text("External Storage permissions granted :)")));
|
||||||
} else {
|
} else {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
"External Storage permissions not granted :(")));
|
"External Storage permissions not granted :(")));
|
||||||
}
|
}
|
||||||
@ -109,10 +109,10 @@ class _MyBodyState extends State<Body> {
|
|||||||
child: Text("checkLocationEnabled"),
|
child: Text("checkLocationEnabled"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await Nearby().checkLocationEnabled()) {
|
if (await Nearby().checkLocationEnabled()) {
|
||||||
Scaffold.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Location is ON :)")));
|
SnackBar(content: Text("Location is ON :)")));
|
||||||
} else {
|
} else {
|
||||||
Scaffold.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Location is OFF :(")));
|
SnackBar(content: Text("Location is OFF :(")));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -121,12 +121,12 @@ class _MyBodyState extends State<Body> {
|
|||||||
child: Text("enableLocationServices"),
|
child: Text("enableLocationServices"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (await Nearby().enableLocationServices()) {
|
if (await Nearby().enableLocationServices()) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text("Location Service Enabled :)")));
|
content: Text("Location Service Enabled :)")));
|
||||||
} else {
|
} else {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content:
|
content:
|
||||||
Text("Enabling Location Service Failed :(")));
|
Text("Enabling Location Service Failed :(")));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -148,7 +148,8 @@ class _MyBodyState extends State<Body> {
|
|||||||
showSnackbar(status);
|
showSnackbar(status);
|
||||||
},
|
},
|
||||||
onDisconnected: (id) {
|
onDisconnected: (id) {
|
||||||
showSnackbar("Disconnected: ${endpointMap[id].endpointName}, id $id");
|
showSnackbar(
|
||||||
|
"Disconnected: ${endpointMap[id].endpointName}, id $id");
|
||||||
setState(() {
|
setState(() {
|
||||||
endpointMap.remove(id);
|
endpointMap.remove(id);
|
||||||
});
|
});
|
||||||
@ -205,7 +206,8 @@ class _MyBodyState extends State<Body> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
endpointMap.remove(id);
|
endpointMap.remove(id);
|
||||||
});
|
});
|
||||||
showSnackbar("Disconnected from: ${endpointMap[id].endpointName}, id $id");
|
showSnackbar(
|
||||||
|
"Disconnected from: ${endpointMap[id].endpointName}, id $id");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -217,7 +219,8 @@ class _MyBodyState extends State<Body> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onEndpointLost: (id) {
|
onEndpointLost: (id) {
|
||||||
showSnackbar("Lost discovered Endpoint: ${endpointMap[id].endpointName}, id $id");
|
showSnackbar(
|
||||||
|
"Lost discovered Endpoint: ${endpointMap[id].endpointName}, id $id");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
showSnackbar("DISCOVERING: " + a.toString());
|
showSnackbar("DISCOVERING: " + a.toString());
|
||||||
@ -255,20 +258,23 @@ class _MyBodyState extends State<Body> {
|
|||||||
String a = Random().nextInt(100).toString();
|
String a = Random().nextInt(100).toString();
|
||||||
|
|
||||||
showSnackbar("Sending $a to ${value.endpointName}, id: $key");
|
showSnackbar("Sending $a to ${value.endpointName}, id: $key");
|
||||||
Nearby().sendBytesPayload(key, Uint8List.fromList(a.codeUnits));
|
Nearby()
|
||||||
|
.sendBytesPayload(key, Uint8List.fromList(a.codeUnits));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
child: Text("Send File Payload"),
|
child: Text("Send File Payload"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
File file =
|
PickedFile file =
|
||||||
await ImagePicker.pickImage(source: ImageSource.gallery);
|
await ImagePicker().getImage(source: ImageSource.gallery);
|
||||||
|
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
for(MapEntry<String, ConnectionInfo> m in endpointMap.entries){
|
for (MapEntry<String, ConnectionInfo> m
|
||||||
int payloadId = await Nearby().sendFilePayload(m.key, file.path);
|
in endpointMap.entries) {
|
||||||
|
int payloadId =
|
||||||
|
await Nearby().sendFilePayload(m.key, file.path);
|
||||||
showSnackbar("Sending file to ${m.key}");
|
showSnackbar("Sending file to ${m.key}");
|
||||||
Nearby().sendBytesPayload(
|
Nearby().sendBytesPayload(
|
||||||
m.key,
|
m.key,
|
||||||
@ -341,7 +347,7 @@ class _MyBodyState extends State<Body> {
|
|||||||
},
|
},
|
||||||
onPayloadTransferUpdate: (endid, payloadTransferUpdate) {
|
onPayloadTransferUpdate: (endid, payloadTransferUpdate) {
|
||||||
if (payloadTransferUpdate.status ==
|
if (payloadTransferUpdate.status ==
|
||||||
PayloadStatus.IN_PROGRRESS) {
|
PayloadStatus.IN_PROGRESS) {
|
||||||
print(payloadTransferUpdate.bytesTransferred);
|
print(payloadTransferUpdate.bytesTransferred);
|
||||||
} else if (payloadTransferUpdate.status ==
|
} else if (payloadTransferUpdate.status ==
|
||||||
PayloadStatus.FAILURE) {
|
PayloadStatus.FAILURE) {
|
||||||
|
@ -122,7 +122,7 @@ packages:
|
|||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "2.0.2"
|
version: "3.0.0-nullsafety.1"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -130,20 +130,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0-nullsafety.3"
|
version: "1.8.0-nullsafety.3"
|
||||||
pedantic:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pedantic
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.9.2"
|
|
||||||
plugin_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: plugin_platform_interface
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.3"
|
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -206,5 +192,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.5"
|
version: "2.1.0-nullsafety.5"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.12.0-0.0 <3.0.0"
|
dart: ">=2.12.0-29.10.beta <3.0.0"
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=1.20.0 <2.0.0"
|
||||||
|
@ -14,11 +14,11 @@ class Payload {
|
|||||||
int id;
|
int id;
|
||||||
PayloadType type;
|
PayloadType type;
|
||||||
|
|
||||||
Uint8List bytes;
|
Uint8List? bytes;
|
||||||
String filePath;
|
String? filePath;
|
||||||
|
|
||||||
Payload({
|
Payload({
|
||||||
this.id,
|
required this.id,
|
||||||
this.bytes,
|
this.bytes,
|
||||||
this.type = PayloadType.NONE,
|
this.type = PayloadType.NONE,
|
||||||
this.filePath,
|
this.filePath,
|
||||||
@ -32,9 +32,9 @@ class PayloadTransferUpdate {
|
|||||||
PayloadStatus status;
|
PayloadStatus status;
|
||||||
|
|
||||||
PayloadTransferUpdate({
|
PayloadTransferUpdate({
|
||||||
this.id,
|
required this.id,
|
||||||
this.bytesTransferred,
|
required this.bytesTransferred,
|
||||||
this.totalBytes,
|
required this.totalBytes,
|
||||||
this.status = PayloadStatus.NONE,
|
this.status = PayloadStatus.NONE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import 'package:nearby_connections/src/classes.dart';
|
|||||||
/// **P2P_POINT_TO_POINT** - single connection, very high bandwidth
|
/// **P2P_POINT_TO_POINT** - single connection, very high bandwidth
|
||||||
enum Strategy { P2P_CLUSTER, P2P_STAR, P2P_POINT_TO_POINT }
|
enum Strategy { P2P_CLUSTER, P2P_STAR, P2P_POINT_TO_POINT }
|
||||||
enum Status { CONNECTED, REJECTED, ERROR }
|
enum Status { CONNECTED, REJECTED, ERROR }
|
||||||
enum PayloadStatus { NONE, SUCCESS, FAILURE, IN_PROGRRESS, CANCELED }
|
enum PayloadStatus { NONE, SUCCESS, FAILURE, IN_PROGRESS, CANCELED }
|
||||||
enum PayloadType { NONE, BYTES, FILE, STREAM }
|
enum PayloadType { NONE, BYTES, FILE, STREAM }
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -29,7 +29,7 @@ typedef void OnDisconnected(String endpointId);
|
|||||||
//
|
//
|
||||||
typedef void OnEndpointFound(
|
typedef void OnEndpointFound(
|
||||||
String endpointId, String endpointName, String serviceId);
|
String endpointId, String endpointName, String serviceId);
|
||||||
typedef void OnEndpointLost(String endpointId);
|
typedef void OnEndpointLost(String? endpointId);
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:nearby_connections/src/classes.dart';
|
import 'package:nearby_connections/src/classes.dart';
|
||||||
import 'package:nearby_connections/src/defs.dart';
|
import 'package:nearby_connections/src/defs.dart';
|
||||||
@ -14,24 +13,24 @@ import 'package:nearby_connections/src/defs.dart';
|
|||||||
/// All methods are asynchronous.
|
/// All methods are asynchronous.
|
||||||
class Nearby {
|
class Nearby {
|
||||||
//Singleton pattern for maintaining only 1 instance of this class
|
//Singleton pattern for maintaining only 1 instance of this class
|
||||||
static Nearby _instance;
|
static Nearby? _instance;
|
||||||
|
|
||||||
factory Nearby() {
|
factory Nearby() {
|
||||||
if (_instance == null) {
|
if (_instance == null) {
|
||||||
_instance = Nearby._();
|
_instance = Nearby._();
|
||||||
}
|
}
|
||||||
return _instance;
|
return _instance!;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nearby._() {
|
Nearby._() {
|
||||||
_channel.setMethodCallHandler((handler) {
|
_channel.setMethodCallHandler((MethodCall handler) {
|
||||||
Map<dynamic, dynamic> args = handler.arguments;
|
Map<dynamic, dynamic> args = handler.arguments!;
|
||||||
switch (handler.method) {
|
switch (handler.method) {
|
||||||
case "ad.onConnectionInitiated":
|
case "ad.onConnectionInitiated":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
String endpointName = args['endpointName'];
|
String endpointName = args['endpointName'] ?? '-1';
|
||||||
String authenticationToken = args['authenticationToken'];
|
String authenticationToken = args['authenticationToken'] ?? '-1';
|
||||||
bool isIncomingConnection = args['isIncomingConnection'];
|
bool isIncomingConnection = args['isIncomingConnection'] ?? false;
|
||||||
|
|
||||||
_advertConnectionInitiated?.call(
|
_advertConnectionInitiated?.call(
|
||||||
endpointId,
|
endpointId,
|
||||||
@ -40,24 +39,25 @@ class Nearby {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "ad.onConnectionResult":
|
case "ad.onConnectionResult":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
Status statusCode = Status.values[args['statusCode']];
|
Status statusCode =
|
||||||
|
Status.values[args['statusCode'] ?? Status.ERROR.index];
|
||||||
|
|
||||||
_advertConnectionResult?.call(endpointId, statusCode);
|
_advertConnectionResult?.call(endpointId, statusCode);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "ad.onDisconnected":
|
case "ad.onDisconnected":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
|
|
||||||
_advertDisconnected?.call(endpointId);
|
_advertDisconnected?.call(endpointId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
case "dis.onConnectionInitiated":
|
case "dis.onConnectionInitiated":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
String endpointName = args['endpointName'];
|
String endpointName = args['endpointName'] ?? '-1';
|
||||||
String authenticationToken = args['authenticationToken'];
|
String authenticationToken = args['authenticationToken'] ?? '-1';
|
||||||
bool isIncomingConnection = args['isIncomingConnection'];
|
bool isIncomingConnection = args['isIncomingConnection'] ?? false;
|
||||||
|
|
||||||
_discoverConnectionInitiated?.call(
|
_discoverConnectionInitiated?.call(
|
||||||
endpointId,
|
endpointId,
|
||||||
@ -66,38 +66,39 @@ class Nearby {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "dis.onConnectionResult":
|
case "dis.onConnectionResult":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
Status statusCode = Status.values[args['statusCode']];
|
Status statusCode =
|
||||||
|
Status.values[args['statusCode'] ?? Status.ERROR.index];
|
||||||
|
|
||||||
_discoverConnectionResult?.call(endpointId, statusCode);
|
_discoverConnectionResult?.call(endpointId, statusCode);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "dis.onDisconnected":
|
case "dis.onDisconnected":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
|
|
||||||
_discoverDisconnected?.call(endpointId);
|
_discoverDisconnected?.call(endpointId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
case "dis.onEndpointFound":
|
case "dis.onEndpointFound":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
String endpointName = args['endpointName'];
|
String endpointName = args['endpointName'] ?? '-1';
|
||||||
String serviceId = args['serviceId'];
|
String serviceId = args['serviceId'] ?? '-1';
|
||||||
_onEndpointFound?.call(endpointId, endpointName, serviceId);
|
_onEndpointFound?.call(endpointId, endpointName, serviceId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "dis.onEndpointLost":
|
case "dis.onEndpointLost":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
|
|
||||||
_onEndpointLost?.call(endpointId);
|
_onEndpointLost?.call(endpointId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case "onPayloadReceived":
|
case "onPayloadReceived":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
int type = args['type'];
|
int type = args['type'] ?? PayloadType.NONE;
|
||||||
Uint8List bytes = args['bytes'];
|
Uint8List bytes = args['bytes'] ?? Uint8List(0);
|
||||||
int payloadId = args['payloadId'];
|
int payloadId = args['payloadId'] ?? -1;
|
||||||
String filePath = args['filePath'];
|
String filePath = args['filePath'] ?? '';
|
||||||
|
|
||||||
Payload payload = Payload(
|
Payload payload = Payload(
|
||||||
type: PayloadType.values[type],
|
type: PayloadType.values[type],
|
||||||
@ -110,11 +111,11 @@ class Nearby {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case "onPayloadTransferUpdate":
|
case "onPayloadTransferUpdate":
|
||||||
String endpointId = args['endpointId'];
|
String endpointId = args['endpointId'] ?? '-1';
|
||||||
int payloadId = args['payloadId'];
|
int payloadId = args['payloadId'] ?? -1;
|
||||||
int status = args['status'];
|
int status = args['status'] ?? Status.ERROR.index;
|
||||||
int bytesTransferred = args['bytesTransferred'];
|
int bytesTransferred = args['bytesTransferred'] ?? 0;
|
||||||
int totalBytes = args['totalBytes'];
|
int totalBytes = args['totalBytes'] ?? 0;
|
||||||
|
|
||||||
PayloadTransferUpdate payloadTransferUpdate = PayloadTransferUpdate(
|
PayloadTransferUpdate payloadTransferUpdate = PayloadTransferUpdate(
|
||||||
id: payloadId,
|
id: payloadId,
|
||||||
@ -127,22 +128,22 @@ class Nearby {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
} as Future<dynamic> Function(MethodCall)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
//for advertisers
|
//for advertisers
|
||||||
OnConnectionInitiated _advertConnectionInitiated,
|
OnConnectionInitiated? _advertConnectionInitiated,
|
||||||
_discoverConnectionInitiated;
|
_discoverConnectionInitiated;
|
||||||
OnConnectionResult _advertConnectionResult, _discoverConnectionResult;
|
OnConnectionResult? _advertConnectionResult, _discoverConnectionResult;
|
||||||
OnDisconnected _advertDisconnected, _discoverDisconnected;
|
OnDisconnected? _advertDisconnected, _discoverDisconnected;
|
||||||
|
|
||||||
//for discoverers
|
//for discoverers
|
||||||
OnEndpointFound _onEndpointFound;
|
OnEndpointFound? _onEndpointFound;
|
||||||
OnEndpointLost _onEndpointLost;
|
OnEndpointLost? _onEndpointLost;
|
||||||
|
|
||||||
//for receiving payload
|
//for receiving payload
|
||||||
OnPayloadReceived _onPayloadReceived;
|
OnPayloadReceived? _onPayloadReceived;
|
||||||
OnPayloadTransferUpdate _onPayloadTransferUpdate;
|
OnPayloadTransferUpdate? _onPayloadTransferUpdate;
|
||||||
|
|
||||||
static const MethodChannel _channel =
|
static const MethodChannel _channel =
|
||||||
const MethodChannel('nearby_connections');
|
const MethodChannel('nearby_connections');
|
||||||
@ -151,21 +152,23 @@ class Nearby {
|
|||||||
///
|
///
|
||||||
/// returns true/false based on location permissions.
|
/// returns true/false based on location permissions.
|
||||||
/// Discovery cannot be started with insufficient permission
|
/// Discovery cannot be started with insufficient permission
|
||||||
Future<bool> checkLocationPermission() async => await _channel.invokeMethod(
|
Future<bool> checkLocationPermission() async =>
|
||||||
|
await _channel.invokeMethod(
|
||||||
'checkLocationPermission',
|
'checkLocationPermission',
|
||||||
);
|
) ??
|
||||||
|
false;
|
||||||
|
|
||||||
/// convenience method
|
/// convenience method
|
||||||
///
|
///
|
||||||
/// Asks location permission
|
/// Asks location permission
|
||||||
Future<bool> askLocationPermission() async =>
|
Future<bool> askLocationPermission() async =>
|
||||||
await _channel.invokeMethod('askLocationPermission');
|
await _channel.invokeMethod('askLocationPermission') ?? false;
|
||||||
|
|
||||||
/// convenience method
|
/// convenience method
|
||||||
///
|
///
|
||||||
/// returns true/false based on external storage permissions.
|
/// returns true/false based on external storage permissions.
|
||||||
Future<bool> checkExternalStoragePermission() async =>
|
Future<bool> checkExternalStoragePermission() async =>
|
||||||
await _channel.invokeMethod('checkExternalStoragePermission');
|
await _channel.invokeMethod('checkExternalStoragePermission') ?? false;
|
||||||
|
|
||||||
/// convenience method
|
/// convenience method
|
||||||
///
|
///
|
||||||
@ -174,13 +177,13 @@ class Nearby {
|
|||||||
/// If Location isn't enabled, devices may disconnect often.
|
/// If Location isn't enabled, devices may disconnect often.
|
||||||
/// Some devices may immediately disconnect
|
/// Some devices may immediately disconnect
|
||||||
Future<bool> checkLocationEnabled() async =>
|
Future<bool> checkLocationEnabled() async =>
|
||||||
await _channel.invokeMethod('checkLocationEnabled');
|
await _channel.invokeMethod('checkLocationEnabled') ?? false;
|
||||||
|
|
||||||
/// convenience method
|
/// convenience method
|
||||||
///
|
///
|
||||||
/// directs user to Location Settings, so they can turn on their Location/GPS
|
/// directs user to Location Settings, so they can turn on their Location/GPS
|
||||||
Future<bool> enableLocationServices() async =>
|
Future<bool> enableLocationServices() async =>
|
||||||
await _channel.invokeMethod('enableLocationServices');
|
await _channel.invokeMethod('enableLocationServices') ?? false;
|
||||||
|
|
||||||
/// convenience method
|
/// convenience method
|
||||||
///
|
///
|
||||||
@ -201,22 +204,21 @@ class Nearby {
|
|||||||
Future<bool> startAdvertising(
|
Future<bool> startAdvertising(
|
||||||
String userNickName,
|
String userNickName,
|
||||||
Strategy strategy, {
|
Strategy strategy, {
|
||||||
@required OnConnectionInitiated onConnectionInitiated,
|
required OnConnectionInitiated onConnectionInitiated,
|
||||||
@required OnConnectionResult onConnectionResult,
|
required OnConnectionResult onConnectionResult,
|
||||||
@required OnDisconnected onDisconnected,
|
required OnDisconnected onDisconnected,
|
||||||
String serviceId = "com.pkmnapps.nearby_connections",
|
String serviceId = "com.pkmnapps.nearby_connections",
|
||||||
}) async {
|
}) async {
|
||||||
assert(userNickName != null && strategy != null && serviceId != null);
|
|
||||||
|
|
||||||
this._advertConnectionInitiated = onConnectionInitiated;
|
this._advertConnectionInitiated = onConnectionInitiated;
|
||||||
this._advertConnectionResult = onConnectionResult;
|
this._advertConnectionResult = onConnectionResult;
|
||||||
this._advertDisconnected = onDisconnected;
|
this._advertDisconnected = onDisconnected;
|
||||||
|
|
||||||
return await _channel.invokeMethod('startAdvertising', <String, dynamic>{
|
return await _channel.invokeMethod('startAdvertising', <String, dynamic>{
|
||||||
'userNickName': userNickName,
|
'userNickName': userNickName,
|
||||||
'strategy': strategy.index,
|
'strategy': strategy.index,
|
||||||
'serviceId': serviceId,
|
'serviceId': serviceId,
|
||||||
});
|
}) ??
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop Advertising
|
/// Stop Advertising
|
||||||
@ -236,19 +238,19 @@ class Nearby {
|
|||||||
Future<bool> startDiscovery(
|
Future<bool> startDiscovery(
|
||||||
String userNickName,
|
String userNickName,
|
||||||
Strategy strategy, {
|
Strategy strategy, {
|
||||||
@required OnEndpointFound onEndpointFound,
|
required OnEndpointFound onEndpointFound,
|
||||||
@required OnEndpointLost onEndpointLost,
|
required OnEndpointLost onEndpointLost,
|
||||||
String serviceId = "com.pkmnapps.nearby_connections",
|
String serviceId = "com.pkmnapps.nearby_connections",
|
||||||
}) async {
|
}) async {
|
||||||
assert(userNickName != null && strategy != null && serviceId != null);
|
|
||||||
this._onEndpointFound = onEndpointFound;
|
this._onEndpointFound = onEndpointFound;
|
||||||
this._onEndpointLost = onEndpointLost;
|
this._onEndpointLost = onEndpointLost;
|
||||||
|
|
||||||
return await _channel.invokeMethod('startDiscovery', <String, dynamic>{
|
return await _channel.invokeMethod('startDiscovery', <String, dynamic>{
|
||||||
'userNickName': userNickName,
|
'userNickName': userNickName,
|
||||||
'strategy': strategy.index,
|
'strategy': strategy.index,
|
||||||
'serviceId': serviceId,
|
'serviceId': serviceId,
|
||||||
});
|
}) ??
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop Discovery
|
/// Stop Discovery
|
||||||
@ -278,7 +280,6 @@ class Nearby {
|
|||||||
/// this will call the onDisconnected method on callbacks of
|
/// this will call the onDisconnected method on callbacks of
|
||||||
/// connected endPoint
|
/// connected endPoint
|
||||||
Future<void> disconnectFromEndpoint(String endpointId) async {
|
Future<void> disconnectFromEndpoint(String endpointId) async {
|
||||||
assert(endpointId != null);
|
|
||||||
await _channel.invokeMethod(
|
await _channel.invokeMethod(
|
||||||
'disconnectFromEndpoint', <String, dynamic>{'endpointId': endpointId});
|
'disconnectFromEndpoint', <String, dynamic>{'endpointId': endpointId});
|
||||||
}
|
}
|
||||||
@ -293,24 +294,22 @@ class Nearby {
|
|||||||
Future<bool> requestConnection(
|
Future<bool> requestConnection(
|
||||||
String userNickName,
|
String userNickName,
|
||||||
String endpointId, {
|
String endpointId, {
|
||||||
@required OnConnectionInitiated onConnectionInitiated,
|
required OnConnectionInitiated onConnectionInitiated,
|
||||||
@required OnConnectionResult onConnectionResult,
|
required OnConnectionResult onConnectionResult,
|
||||||
@required OnDisconnected onDisconnected,
|
required OnDisconnected onDisconnected,
|
||||||
}) async {
|
}) async {
|
||||||
this._discoverConnectionInitiated = onConnectionInitiated;
|
this._discoverConnectionInitiated = onConnectionInitiated;
|
||||||
this._discoverConnectionResult = onConnectionResult;
|
this._discoverConnectionResult = onConnectionResult;
|
||||||
this._discoverDisconnected = onDisconnected;
|
this._discoverDisconnected = onDisconnected;
|
||||||
|
|
||||||
assert(endpointId != null);
|
|
||||||
assert(userNickName != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'requestConnection',
|
'requestConnection',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'userNickName': userNickName,
|
'userNickName': userNickName,
|
||||||
'endpointId': endpointId,
|
'endpointId': endpointId,
|
||||||
},
|
},
|
||||||
);
|
) ??
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Needs be called by both discoverer and advertiser
|
/// Needs be called by both discoverer and advertiser
|
||||||
@ -323,20 +322,19 @@ class Nearby {
|
|||||||
/// only if both of them accept the connection
|
/// only if both of them accept the connection
|
||||||
Future<bool> acceptConnection(
|
Future<bool> acceptConnection(
|
||||||
String endpointId, {
|
String endpointId, {
|
||||||
@required OnPayloadReceived onPayLoadRecieved,
|
required OnPayloadReceived onPayLoadRecieved,
|
||||||
OnPayloadTransferUpdate onPayloadTransferUpdate,
|
OnPayloadTransferUpdate? onPayloadTransferUpdate,
|
||||||
}) async {
|
}) async {
|
||||||
this._onPayloadReceived = onPayLoadRecieved;
|
this._onPayloadReceived = onPayLoadRecieved;
|
||||||
this._onPayloadTransferUpdate = onPayloadTransferUpdate;
|
this._onPayloadTransferUpdate = onPayloadTransferUpdate;
|
||||||
|
|
||||||
assert(endpointId != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'acceptConnection',
|
'acceptConnection',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'endpointId': endpointId,
|
'endpointId': endpointId,
|
||||||
},
|
},
|
||||||
);
|
) ??
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reject Connection
|
/// Reject Connection
|
||||||
@ -349,14 +347,13 @@ class Nearby {
|
|||||||
/// [OnConnectionResult] is called on both
|
/// [OnConnectionResult] is called on both
|
||||||
/// even if one of them rejects the connection
|
/// even if one of them rejects the connection
|
||||||
Future<bool> rejectConnection(String endpointId) async {
|
Future<bool> rejectConnection(String endpointId) async {
|
||||||
assert(endpointId != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'rejectConnection',
|
'rejectConnection',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'endpointId': endpointId,
|
'endpointId': endpointId,
|
||||||
},
|
},
|
||||||
);
|
) ??
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send bytes [Uint8List] payload to endpoint
|
/// Send bytes [Uint8List] payload to endpoint
|
||||||
@ -374,8 +371,6 @@ class Nearby {
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
Future<void> sendBytesPayload(String endpointId, Uint8List bytes) async {
|
Future<void> sendBytesPayload(String endpointId, Uint8List bytes) async {
|
||||||
assert(endpointId != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'sendPayload',
|
'sendPayload',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
@ -392,9 +387,7 @@ class Nearby {
|
|||||||
/// You must also send a bytes payload to send the filename and extension
|
/// You must also send a bytes payload to send the filename and extension
|
||||||
/// so that receiver can rename the file accordingly
|
/// so that receiver can rename the file accordingly
|
||||||
/// Send the payloadID and filename to receiver as bytes payload
|
/// Send the payloadID and filename to receiver as bytes payload
|
||||||
Future<int> sendFilePayload(String endpointId, String filePath) async {
|
Future<int?> sendFilePayload(String endpointId, String filePath) async {
|
||||||
assert(endpointId != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'sendFilePayload',
|
'sendFilePayload',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
@ -406,8 +399,6 @@ class Nearby {
|
|||||||
|
|
||||||
/// Use it to cancel/stop a payload transfer
|
/// Use it to cancel/stop a payload transfer
|
||||||
Future<void> cancelPayload(int payloadId) async {
|
Future<void> cancelPayload(int payloadId) async {
|
||||||
assert(payloadId != null);
|
|
||||||
|
|
||||||
return await _channel.invokeMethod(
|
return await _channel.invokeMethod(
|
||||||
'cancelPayload',
|
'cancelPayload',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
|
@ -143,5 +143,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.5"
|
version: "2.1.0-nullsafety.5"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.12.0-0.0 <3.0.0"
|
dart: ">=2.12.0-29.10.beta <3.0.0"
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=1.20.0 <2.0.0"
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
name: nearby_connections
|
name: nearby_connections
|
||||||
description: Plugin for the android NearbyConnections API. Bytes and Files Supported.
|
description: Plugin for the android NearbyConnections API. Bytes and Files Supported.
|
||||||
version: 2.0.2
|
version: 3.0.0-nullsafety.1
|
||||||
homepage: https://github.com/mannprerak2/nearby_connections
|
homepage: https://github.com/mannprerak2/nearby_connections
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.1.0 <3.0.0"
|
sdk: '>=2.12.0-29.10.beta <3.0.0'
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=1.20.0 <2.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user