@ -33,7 +33,7 @@ class Body extends StatefulWidget {
}
}
class _MyBodyState extends State < Body > {
class _MyBodyState extends State < Body > {
final String userName = Random ( ) . nextInt ( 1000 ) . toString ( ) ;
final String userName = Random ( ) . nextInt ( 1000 0 ) . toString ( ) ;
final Strategy strategy = Strategy . P2P_STAR ;
final Strategy strategy = Strategy . P2P_STAR ;
String cId = " 0 " ; / / currently connected device ID
String cId = " 0 " ; / / currently connected device ID
File tempFile ; / / stores the file being transferred
File tempFile ; / / stores the file being transferred
@ -42,158 +42,185 @@ class _MyBodyState extends State<Body> {
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
return Center (
return Center (
child: Column (
child: Padding (
children: < Widget > [
padding: const EdgeInsets . all ( 8.0 ) ,
Wrap (
child: ListView (
children: < Widget > [
children: < Widget > [
RaisedButton (
Text ( " Permissions " , ) ,
child: Text ( " checkPermission " ) ,
Wrap (
onPressed: ( ) async {
children: < Widget > [
if ( await Nearby ( ) . checkPermissions ( ) ) {
RaisedButton (
Scaffold . of ( context ) . showSnackBar ( SnackBar (
child: Text ( " checkLocationPermission " ) ,
content: Text ( " Location permissions granted :) " ) ) ) ;
onPressed: ( ) async {
} else {
if ( await Nearby ( ) . checkLocationPermission ( ) ) {
Scaffold . of ( context ) . showSnackBar ( SnackBar (
Scaffold . of ( context ) . showSnackBar ( SnackBar (
content: Text ( " Location permissions not granted :( " ) ) ) ;
content: Text ( " Location permissions granted :) " ) ) ) ;
}
} else {
} ,
Scaffold . of ( context ) . showSnackBar ( SnackBar (
) ,
content: Text ( " Location permissions not granted :( " ) ) ) ;
RaisedButton (
}
child: Text ( " askPermission " ) ,
} ,
onPressed: ( ) async {
) ,
await Nearby ( ) . askPermission ( ) ;
RaisedButton (
} ,
child: Text ( " askLocationPermission " ) ,
) ,
onPressed: ( ) async {
] ,
await Nearby ( ) . askLocationPermission ( ) ;
) ,
} ,
Text ( " User Name: " + userName ) ,
) ,
Wrap (
RaisedButton (
children: < Widget > [
child: Text ( " checkExternalStoragePermission " ) ,
RaisedButton (
onPressed: ( ) async {
child: Text ( " Start Advertising " ) ,
if ( await Nearby ( ) . checkExternalStoragePermission ( ) ) {
onPressed: ( ) async {
Scaffold . of ( context ) . showSnackBar ( SnackBar (
try {
content:
bool a = await Nearby ( ) . startAdvertising (
Text ( " External Storage permissions granted :) " ) ) ) ;
userName ,
} else {
strategy ,
Scaffold . of ( context ) . showSnackBar ( SnackBar (
onConnectionInitiated: ( id , info ) {
content: Text (
oci ( id , info ) ;
" External Storage permissions not granted :( " ) ) ) ;
} ,
}
onConnectionResult: ( id , status ) {
} ,
showSnackbar ( status ) ;
) ,
} ,
RaisedButton (
onDisconnected: ( id ) {
child: Text ( " askExternalStoragePermission " ) ,
showSnackbar ( " Disconnected: " + id ) ;
onPressed: ( ) async {
} ,
await Nearby ( ) . askExternalStoragePermission ( ) ;
) ;
} ,
showSnackbar ( a ) ;
) ,
} catch ( exception ) {
] ,
showSnackbar ( exception ) ;
) ,
}
Divider ( ) ,
} ,
Text ( " User Name: " + userName ) ,
) ,
Wrap (
RaisedButton (
children: < Widget > [
child: Text ( " Stop Advertising " ) ,
RaisedButton (
onPressed: ( ) async {
child: Text ( " Start Advertising " ) ,
await Nearby ( ) . stopAdvertising ( ) ;
onPressed: ( ) async {
} ,
try {
) ,
bool a = await Nearby ( ) . startAdvertising (
] ,
userName ,
) ,
strategy ,
Wrap (
onConnectionInitiated: ( id , info ) {
children: < Widget > [
oci ( id , info ) ;
RaisedButton (
} ,
child: Text ( " Start Discovery " ) ,
onConnectionResult: ( id , status ) {
onPressed: ( ) async {
showSnackbar ( status ) ;
try {
} ,
bool a = await Nearby ( ) . startDiscovery (
onDisconnected: ( id ) {
userName ,
showSnackbar ( " Disconnected: " + id ) ;
strategy ,
} ,
onEndpointFound: ( id , name , serviceId ) {
) ;
print ( " in callback " ) ;
showSnackbar ( a ) ;
showModalBottomSheet (
} catch ( exception ) {
context: context ,
showSnackbar ( exception ) ;
builder: ( builder ) {
}
return Center (
} ,
child: Column (
) ,
children: < Widget > [
RaisedButton (
Text ( " id: " + id ) ,
child: Text ( " Stop Advertising " ) ,
Text ( " Name: " + name ) ,
onPressed: ( ) async {
Text ( " ServiceId: " + serviceId ) ,
await Nearby ( ) . stopAdvertising ( ) ;
RaisedButton (
} ,
child: Text ( " Request Connection " ) ,
) ,
onPressed: ( ) {
] ,
Navigator . pop ( context ) ;
) ,
Nearby ( ) . requestConnection (
Wrap (
userName ,
children: < Widget > [
id ,
RaisedButton (
onConnectionInitiated: ( id , info ) {
child: Text ( " Start Discovery " ) ,
oci ( id , info ) ;
onPressed: ( ) async {
} ,
try {
onConnectionResult: ( id , status ) {
bool a = await Nearby ( ) . startDiscovery (
showSnackbar ( status ) ;
userName ,
} ,
strategy ,
onDisconnected: ( id ) {
onEndpointFound: ( id , name , serviceId ) {
showSnackbar ( id ) ;
print ( " in callback " ) ;
} ,
showModalBottomSheet (
) ;
context: context ,
} ,
builder: ( builder ) {
) ,
return Center (
] ,
child: Column (
) ,
children: < Widget > [
) ;
Text ( " id: " + id ) ,
} ,
Text ( " Name: " + name ) ,
) ;
Text ( " ServiceId: " + serviceId ) ,
} ,
RaisedButton (
onEndpointLost: ( id ) {
child: Text ( " Request Connection " ) ,
showSnackbar ( id ) ;
onPressed: ( ) {
} ,
Navigator . pop ( context ) ;
) ;
Nearby ( ) . requestConnection (
showSnackbar ( a ) ;
userName ,
} catch ( e ) {
id ,
showSnackbar ( e ) ;
onConnectionInitiated: ( id , info ) {
}
oci ( id , info ) ;
} ,
} ,
) ,
onConnectionResult: ( id , status ) {
RaisedButton (
showSnackbar ( status ) ;
child: Text ( " Stop Discovery " ) ,
} ,
onPressed: ( ) async {
onDisconnected: ( id ) {
await Nearby ( ) . stopDiscovery ( ) ;
showSnackbar ( id ) ;
} ,
} ,
) ,
) ;
] ,
} ,
) ,
) ,
RaisedButton (
] ,
child: Text ( " Stop All Endpoints " ) ,
) ,
onPressed: ( ) async {
) ;
await Nearby ( ) . stopAllEndpoints ( ) ;
} ,
} ,
) ;
) ,
} ,
RaisedButton (
onEndpointLost: ( id ) {
child: Text ( " Send Random Bytes Payload " ) ,
showSnackbar ( id ) ;
onPressed: ( ) async {
} ,
String a = Random ( ) . nextInt ( 100 ) . toString ( ) ;
) ;
showSnackbar ( " Sending $ a to $ cId " ) ;
showSnackbar ( a ) ;
Nearby ( ) . sendBytesPayload ( cId , Uint8List . fromList ( a . codeUnits ) ) ;
} catch ( e ) {
} ,
showSnackbar ( e ) ;
) ,
}
RaisedButton (
} ,
child: Text ( " Send File Payload " ) ,
) ,
onPressed: ( ) async {
RaisedButton (
File file =
child: Text ( " Stop Discovery " ) ,
await ImagePicker . pickImage ( source : ImageSource . gallery ) ;
onPressed: ( ) async {
await Nearby ( ) . stopDiscovery ( ) ;
} ,
) ,
] ,
) ,
RaisedButton (
child: Text ( " Stop All Endpoints " ) ,
onPressed: ( ) async {
await Nearby ( ) . stopAllEndpoints ( ) ;
} ,
) ,
Divider ( ) ,
Text ( " Sending Data " , ) ,
RaisedButton (
child: Text ( " Send Random Bytes Payload " ) ,
onPressed: ( ) async {
String a = Random ( ) . nextInt ( 100 ) . toString ( ) ;
showSnackbar ( " Sending $ a to $ cId " ) ;
Nearby ( ) . sendBytesPayload ( cId , Uint8List . fromList ( a . codeUnits ) ) ;
} ,
) ,
RaisedButton (
child: Text ( " Send File Payload " ) ,
onPressed: ( ) async {
File file =
await ImagePicker . pickImage ( source : ImageSource . gallery ) ;
if ( file = = null ) return ;
if ( file = = null ) return ;
int payloadId = await Nearby ( ) . sendFilePayload ( cId , file . path ) ;
int payloadId = await Nearby ( ) . sendFilePayload ( cId , file . path ) ;
showSnackbar ( " Sending file to $ cId " ) ;
showSnackbar ( " Sending file to $ cId " ) ;
Nearby ( ) . sendBytesPayload (
Nearby ( ) . sendBytesPayload (
cId ,
cId ,
Uint8List . fromList (
Uint8List . fromList (
" $ payloadId : ${ file . path . split ( ' / ' ) . last } " . codeUnits ) ) ;
" $ payloadId : ${ file . path . split ( ' / ' ) . last } " . codeUnits ) ) ;
} ,
} ,
) ,
) ,
] ,
] ,
) ,
) ,
) ,
) ;
) ;
}
}
@ -261,11 +288,9 @@ class _MyBodyState extends State<Body> {
showSnackbar ( endid + " : FAILED to transfer file " ) ;
showSnackbar ( endid + " : FAILED to transfer file " ) ;
} else if ( payloadTransferUpdate . status = =
} else if ( payloadTransferUpdate . status = =
PayloadStatus . SUCCESS ) {
PayloadStatus . SUCCESS ) {
print (
showSnackbar (
" success, total bytes = ${ payloadTransferUpdate . totalBytes } " ) ;
" success, total bytes = ${ payloadTransferUpdate . totalBytes } " ) ;
showSnackbar ( endid +
" : SUCCESS in file transfer (file is un-named in downloads) " ) ;
if ( map . containsKey ( payloadTransferUpdate . id ) ) {
if ( map . containsKey ( payloadTransferUpdate . id ) ) {
/ / rename the file now
/ / rename the file now
String name = map [ payloadTransferUpdate . id ] ;
String name = map [ payloadTransferUpdate . id ] ;