flutter_beacon 0.2.3 flutter_beacon: ^0.2.3 copied to clipboard
Flutter plugin for scanning beacon (iBeacon platform) devices on Android and iOS.
flutter_beacon #
Flutter plugin to work with iBeacons.
An hybrid iBeacon scanner SDK for Flutter plugin. Supports Android API 18+ and iOS 8+.
Features:
- Automatic permission management
- Ranging iBeacons
- Monitoring iBeacons
Installation #
Add to pubspec.yaml:
dependencies:
flutter_beacon: ^0.2.3
Setup specific for Android #
Nothing.
Setup specific for iOS #
In order to use beacons related features, apps are required to ask the location permission. It's a two step process:
- Declare the permission the app requires in configuration files
- Request the permission to the user when app is running (the plugin can handle this automatically)
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>
</dict>
How-to #
Ranging APIs are designed as reactive streams.
- The first subscription to the stream will start the ranging
Initializing Library #
try {
await flutterBeacon.initializeScanning;
} on PlatformException catch(e) {
// library failed to initialize, check code and message
}
Ranging beacons #
final regions = <Region>[];
if (Platform.isIOS) {
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();
Monitoring beacons #
final regions = <Region>[];
if (Platform.isIOS) {
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();
Under the hood #
- iOS uses native iOS CoreLocation
- Android uses the third-party library android-beacon-library (Apache License 2.0)
Author #
Flutter Beacon plugin is developed by Alann Maulana. You can contact me at kangmas.alan@gmail.com.
License #
Apache License 2.0