flutter_beacon
Flutter plugin for scanning and transmit as beacon (iBeacon) on Android and iOS.
An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
{"sdk":"flutter"}{"sdk":"flutter"}English project snapshot. Visit GitHub for the latest content.
Pub GitHub Build Coverage Status FOSSA Status codecov
Flutter plugin to work with iBeacons.
An hybrid iBeacon scanner and transmitter SDK for Flutter plugin. Supports Android API 18+ and iOS 8+.
Features:
Add to pubspec.yaml:
dependencies:
flutter_beacon: latest
For target SDK version 29+ (Android 10, 11) is necessary to add manually ACCESS_FINE_LOCATION
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and if you want also background scanning:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
In order to use beacons related features, apps are required to ask the location permission. It's a two step process:
The needed permissions in iOS is when in use.
For more details about what you can do with each permission, see:
https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services
Permission must be declared in ios/Runner/Info.plist:
<dict>
<!-- When in use -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>Reason why app needs location</string>
<!-- Always -->
<!-- for iOS 11 + -->
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Reason why app needs location</string>
<!-- for iOS 9/10 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>Reason why app needs location</string>
<!-- Bluetooth Privacy -->
<!-- for iOS 13 + -->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Reason why app needs bluetooth</string>
</dict>
Ranging APIs are designed as reactive streams.
try {
// if you want to manage manual checking about the required permissions
await flutterBeacon.initializeScanning;
// or if you want to include automatic checking permission
await flutterBeacon.initializeAndCheckScanning;
} on PlatformException catch(e) {
// library failed to initialize, check code and message
}
final regions = <Region>[];
if (Platform.isIOS) {
// iOS platform, at least set identifier and proximityUUID for region scanning
regions.add(Region(
identifier: 'Apple Airlocate',
proximityUUID: 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'));
} else {
// android platform, it can ranging out of beacon that filter all of Proximity UUID
regions.add(Region(identifier: 'com.beacon'));
}
// to start ranging beacons
_streamRanging = flutterBeacon.ranging(regions).listen((RangingResult result) {
// result contains a region and list of beacons found
// list can be empty if no matching beacons were found in range
});
// to stop ranging beacons
_streamRanging.cancel();
final regions = <Region>[];
if (Platform.isIOS) {
// iOS platform, at least set identifier and proximityUUID for region scanning
regions.add(Region(
identifier: 'Apple Airlocate',
proximityUUID: 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'));
} else {
// Android platform, it can ranging out of beacon that filter all of Proximity UUID
regions.add(Region(identifier: 'com.beacon'));
}
// to start monitoring beacons
_streamMonitoring = flutterBeacon.monitoring(regions).listen((MonitoringResult result) {
// result contains a region, event type and event state
});
// to stop monitoring beacons
_streamMonitoring.cancel();
Flutter Beacon plugin is developed by Eyro Labs. You can contact me at <maulana@cubeacon.com>.