mirror of
				https://github.com/hackku21/nearby_connections.git
				synced 2025-06-13 12:53:50 +00:00 
			
		
		
		
	published 1.0.0
This commit is contained in:
		
							parent
							
								
									4d666c42a5
								
							
						
					
					
						commit
						dcd86e885f
					
				| @ -132,15 +132,20 @@ File is stored in DOWNLOAD_DIRECTORY and given a generic name | ||||
| So you would need to rename the file on receivers end. | ||||
| 
 | ||||
| ```dart | ||||
| 
 | ||||
| //creates file with generic name (without extension) in Downloads Directory | ||||
| Nearby().sendFilePayload(endpointId, filePath); | ||||
| 
 | ||||
| //Send filename as well so that receiver can rename the file | ||||
| Nearby().sendBytesPayload(endpointId,fileNameEncoded); | ||||
| Nearby().sendBytesPayload(endpointId,fileNameEncodedWithPayloadId); | ||||
| //e.g send a string like "payloadId:FileExtensionOrName" as bytes | ||||
| 
 | ||||
| //payloads are recieved by callback given to acceptConnection method. | ||||
| ``` | ||||
| Every payload has an **ID** which is same for sender and receiver. | ||||
| 
 | ||||
| You can get the absolute FilePath from Payload in *onPayloadReceived* function | ||||
| 
 | ||||
| Check **Example** in Repository for more details | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -358,6 +358,9 @@ public class NearbyConnectionsPlugin implements MethodCallHandler { | ||||
|                 assert bytes != null; | ||||
|                 args.put("bytes", bytes); | ||||
|             } | ||||
|             else if (payload.getType() == Payload.Type.BYTES) { | ||||
|                 args.put("filePath", payload.asFile().asJavaFile().getAbsolutePath()); | ||||
|             } | ||||
| 
 | ||||
|             channel.invokeMethod("onPayloadReceived", args); | ||||
|         } | ||||
|  | ||||
| @ -4,15 +4,24 @@ import 'dart:typed_data'; | ||||
| import 'package:nearby_connections/src/defs.dart'; | ||||
| 
 | ||||
| /// Bytes may be null if [Payload.type] is not [PayloadType.BYTES]  | ||||
| /// File may be null if [Payload.type] is not [PayloadType.FILE]  | ||||
| ///  | ||||
| /// Filepath is the complete filepath(with name) of the file | ||||
| ///  | ||||
| /// The file at this location is incomplete until payloadTransferUpdate | ||||
| /// gives SUCCESS for this payloadId | ||||
| class Payload { | ||||
|   int id; | ||||
|   PayloadType type; | ||||
|    | ||||
|   Uint8List bytes; | ||||
|   String filePath; | ||||
| 
 | ||||
|   Payload({ | ||||
|     this.id, | ||||
|     this.bytes, | ||||
|     this.type = PayloadType.NONE, | ||||
|     this.filePath, | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -96,11 +96,13 @@ class Nearby { | ||||
|           int type = args['type']; | ||||
|           Uint8List bytes = args['bytes']; | ||||
|           int payloadId = args['payloadId']; | ||||
|           String filePath = args['filePath']; | ||||
| 
 | ||||
|           Payload payload = Payload( | ||||
|             type: PayloadType.values[type], | ||||
|             bytes: bytes, | ||||
|             id: payloadId, | ||||
|             filePath: filePath, | ||||
|           ); | ||||
| 
 | ||||
|           _onPayloadReceived?.call(endpointId, payload); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user