搜尋套件、儲存庫與 APP 分類

套件詳情v0.5.1

flutter_beacon

用於在 Android 和 iOS 上掃描並作為信標(iBeacon)傳輸的 Flutter 插件。

AndroidiOS
近 30 天下載
282
喜歡數
88
Pub 分數
140

安裝套件

flutter pub add flutter_beacon

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter Beacon 是一個跨平台插件,可在 Android 和 iOS 裝置上實現藍牙低能耗(BLE)信標掃描與傳輸。它支援 iBeacon 功能,讓開發者能夠偵測附近信標或廣播信標訊號。該插件可無縫整合至 Flutter 應用程式中,為發現與廣告模式提供簡單直覺的 API。適用於基於距離的應用,例如室內導航、資產追蹤與位置感知服務。與兩個平台上的原生 BLE 功能相容。

適用情境

  • 室內導航系統
  • 資產和設備追蹤
  • 近場行銷
  • 基於位置的觸發
  • 智慧零售體驗

主要特色

  • iBeacon 掃描和傳輸
  • 跨平台支援(Android 與 iOS)
  • 簡單的 Flutter API
  • 即時信標檢測
  • 低功耗

適合對象

  • 開發接近性應用的開發者
  • 需要室內定位的應用
  • 零售與酒店解決方案
  • 物聯網裝置整合
  • 基於事件的移動應用

使用建議

  • 兩個平台都需要藍牙權限
  • 後台操作可能受到作業系統限制
  • 在連續掃描期間應監控電池使用情況
  • 準確性取決於環境因素
  • iOS 後台模式需要額外設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Flutter Beacon

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:

  • Automatic permission management
  • Ranging iBeacons
  • Monitoring iBeacons
  • Transmit as iBeacon

Installation

Add to pubspec.yaml:

dependencies:
  flutter_beacon: latest
Setup specific for Android

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" />
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:

  1. Declare the permission the app requires in configuration files
  2. 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>
  <!-- Bluetooth Privacy -->
  <!-- for iOS 13 + -->
  <key>NSBluetoothAlwaysUsageDescription</key>
  <string>Reason why app needs bluetooth</string>
</dict>

iOS Troubleshooting

  • Example code works properly only on physical device (bluetooth on simulator is disabled)
  • How to deploy flutter app on iOS device Instruction
  • If example code don't works on device (beacons not appear), please make sure that you have enabled
    Location and Bluetooth (Settings -> Flutter Beacon)

How-to

Ranging APIs are designed as reactive streams.

  • The first subscription to the stream will start the ranging
Initializing Library
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
}
Ranging beacons
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();
Monitoring beacons
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();

Under the hood

Author

Flutter Beacon plugin is developed by Eyro Labs. You can contact me at <maulana@cubeacon.com>.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。