Package selection guidance compiled from public package information, community data, and project usage.
The nearby_connections package provides Flutter integration with Android's Nearby Connections API, enabling peer-to-peer communication between devices over Bluetooth, Wi-Fi, and NFC. It supports the transfer of both raw bytes and files, making it ideal for local data sharing in proximity-based applications. The plugin is lightweight and designed specifically for Android, leveraging native capabilities for reliable, low-latency connections. It’s useful for collaborative apps, multiplayer games, or file-sharing tools that require direct device-to-device interaction without internet dependency.
Use cases
Local file sharing between devices
Real-time multiplayer game synchronization
Offline data exchange in group settings
Quick setup of device-to-device communication
Collaborative app features without cloud backend
Key features
Supports bytes and file transfers
Uses Android's native Nearby Connections API
Optimized for low-latency, short-range communication
Simple Flutter interface for Android
Built-in discovery and connection management
Suitable for
Android-only apps requiring local device connectivity
Apps needing fast, offline data transfer
Developers building collaborative or social features
Projects avoiding reliance on internet or cloud services
Prototypes for proximity-based interactions
Considerations
Limited to Android platform only
Requires proper permissions (Bluetooth, location)
No iOS support
Depends on device compatibility with Nearby Connections
Background operation may be restricted by Android OS
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
nearby_connections
An ANDROID flutter plugin for the Nearby Connections API
Currently supports Bytes and Files.
Transfer Data between multiple connected devices using fully offline peer to peer networking
Add these to your project's android/src/main/AndroidManifest.xml
<!-- Required for Nearby Connections --><uses-permissionandroid:maxSdkVersion="31"android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permissionandroid:maxSdkVersion="31"android:name="android.permission.CHANGE_WIFI_STATE" /><uses-permissionandroid:maxSdkVersion="30"android:name="android.permission.BLUETOOTH" /><uses-permissionandroid:maxSdkVersion="30"android:name="android.permission.BLUETOOTH_ADMIN" /><uses-permissionandroid:maxSdkVersion="28"android:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permissionandroid:minSdkVersion="29"android:maxSdkVersion="31"android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permissionandroid:minSdkVersion="31"android:name="android.permission.BLUETOOTH_ADVERTISE" /><uses-permissionandroid:minSdkVersion="31"android:name="android.permission.BLUETOOTH_CONNECT" /><uses-permissionandroid:minSdkVersion="31"android:name="android.permission.BLUETOOTH_SCAN" /><uses-permissionandroid:minSdkVersion="32"android:name="android.permission.NEARBY_WIFI_DEVICES" /><!-- Optional: only required for FILE payloads --><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/>
Note: Android 12+ has introduced some new bluetooth permissions - BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, BLUETOOTH_SCAN, which need to be handled as well. You may also need to set compileSdkVersion 32 in your build.gradle file.
Request Permissions
Since ACCESS_FINE_LOCATION, BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, BLUETOOTH_SCAN and READ_EXTERNAL_STORAGE are considered to be dangerous system permissions, in addition to adding them to your manifest, you must request these permissions at runtime.
try {
bool a = awaitNearby().startAdvertising(
userName,
strategy, // https://developers.google.com/nearby/connections/strategies
onConnectionInitiated: (String id,ConnectionInfo info) {
// Called whenever a discoverer requests connection
},
onConnectionResult: (String id,Status status) {
// Called when connection is accepted/rejected
},
onDisconnected: (String id) {
// Callled whenever a discoverer disconnects from advertiser
},
serviceId: "com.yourdomain.appname", // uniquely identifies your app
);
} catch (exception) {
// platform exceptions like unable to start bluetooth or insufficient permissions
}
Discover Advertisers
try {
bool a = awaitNearby().startDiscovery(
userName,
strategy, // https://developers.google.com/nearby/connections/strategies
onEndpointFound: (String id,String userName, String serviceId) {
// called when an advertiser is found
},
onEndpointLost: (String id) {
//called when an advertiser is lost (only if we weren't connected to it )
},
serviceId: "com.yourdomain.appname", // uniquely identifies your app
);
} catch (e) {
// platform exceptions like unable to start bluetooth or insufficient permissions
}
Stopping Advertising and Discovery
Nearby().stopAdvertising();
Nearby().stopDiscovery();
// endpoints already discovered will still be available to connect// even after stopping discovery// You should stop discovery once you have found the intended advertiser// this will reduce chances for disconnection
Request Connection
// to be called by discover whenever an endpoint is found// callbacks are similar to those in startAdvertising methodtry{
Nearby().requestConnection(
userName,
id,
onConnectionInitiated: (id, info) {
},
onConnectionResult: (id, status) {
},
onDisconnected: (id) {
},
);
}catch(exception){
// called if request was invalid
}
Accept Connection
Nearby().acceptConnection(
id,
onPayLoadRecieved: (endpointId, payload) {
// called whenever a payload is recieved.
},
onPayloadTransferUpdate: (endpointId, payloadTransferUpdate) {
// gives status of a payload// e.g success/failure/in_progress// bytes transferred and total bytes etc
}
);
Sending Data
Sending Bytes Payload
Nearby().sendBytesPayload(endpointId, bytes_array);
// payloads are recieved by callback given to acceptConnection method.
Sending File Payload
You need to send the File Payload and File Name seperately.
File is stored in DOWNLOAD_DIRECTORY/.nearby/ and given a generic name.
You need to copy the file to another directory of your choice.
//creates file with generic name (without extension) in Downloads Directory//its your responsibility to rename the file properlyNearby().sendFilePayload(endpointId, filePath);
//Send filename as well so that receiver can move and rename the fileNearby().sendBytesPayload(endpointId,fileNameEncodedWithPayloadId);
//e.g send a string like "payloadId:FileExtensionOrFullName" 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 uri of the file from Payload in onPayloadReceived function.
We have a convenience method to copy the file to a location you want-
// Convenience method to copy file using it's `uri`.final newPath = '${await getExternalStorageDirectory}/$fileName';
awaitNearby().copyFileAndDeleteOriginal(uri, newPath);
Checkout the Example in Repository for more details.