snowm_scanner 0.5.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

snowm_scanner #

A cross platform package for flutter to scan beacons from SnowM Inc.

Getting Started #

Installation #

dependencies:
  snowm_scanner:

Android Configuration

Make use you have flutter_embedding v2 enabled. Add the following code on the manifest file inside <application> tag to enable embedding.

<meta-data
    android:name="flutterEmbedding"
    android:value="2" />

Also, use io.flutter.embedding.android.FlutterActivity as your FlutterActivity

Bluetooth Permission #

Check permission

    BluetoothPermissionState permissionState = await snowmScanner.getPermissionState();

Ask permission

    snowmScanner.requestPermission();

Bluetooth Adapter State #

Check State Once

    BluetoothState bluetoothState = await snowmScanner.getBluetoothState();

Get Status Stream

    snowmScanner.getBluetoothStateStream().listen((bluetoothState){
        // Get the state changed here
    });

Scanner Configuration #

Configure whether to send the scanned information to IOT Core via MQTT protocol. (Optional)

    snowmScanner.configure(enableMqtt: true);

Scanning #

Start Scanning beacons on foreground. Cancel the scanner by calling cancel() on the subscription stream (Will only scan when the app is on foreground or just entered to background and has not been terminated by the OS)

snowmScanner.scanBeacons(uuids: uuids).listen((beacons) {
     // Do anything with beacon
});

Background Scanning (Optional) #

Android configuration #

Create a class that extends FlutterApplication and add the following code on the onCreate function.

import com.snowm.scanner.services.SnowMBackgroundScanningService
import io.flutter.app.FlutterApplication

class MyApplication  : FlutterApplication() {
    override fun onCreate() {
        super.onCreate()
        SnowMBackgroundScanningService.initializeWithApplication(this)
    }
}

Now register the class as your application name on manifest file under name label.

    <application
        android:name=".MyApplication"
        ...

Create a service which extends to SnowMBackgroundScanningService as below. You will get beacons scanned response on the onBeaconsDetected callback with beacons and customData that you can send while scanning.

class BackgroundScanner : SnowMBackgroundScanningService() {

    override fun onBeaconsDetected(beacons: ArrayList<SnowMiBeacon>, customData: HashMap<String,Any>) {
        super.onBeaconsDetected(beacons, customData)
        Log.d("Scanner","Scanned beacons")
        beacons.forEach {
            Log.d("Scanner",it.uuid)
        }
    }
}

Now define the service on the manifest as below

        <service
            android:name="com.snowm.scanner_example.BackgroundScanner"
            android:exported="false">
            <intent-filter>
                <action android:name="com.snowm.scanner.BACKGROUND_SCANNER" />
            </intent-filter>
        </service>

Also define a broadcast receiver to re initilize the scanner if its closed by uncertain events

        <receiver
            android:name="com.snowm.scanner.services.SnowMGeofenceReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

iOS configuration #

Create a class which extends SnowMBackgroundScanningServiceDelegate to receive detection callback.

import Foundation
import CoreLocation
import snowm_scanner

class BackgroundScannerResponse: SnowMBackgroundScanningServiceDelegate {
    static let shared = BackgroundScannerResponse()

    func onLocationUpdated(locations: [CLLocation]) {
        print("on Location change detected");
    }

    func onBeaconDetected(beacons: [SnowMBeacon], customData: Dictionary<String, Any>?) {
        print("onBeacon detected called from background scanner");
    }
}

Now, call the registerScannerDelegate from your AppDelegate class inside didFinishLaunchingWithOptions function.

    BackgroundBeaconScanner.shared.delegate = BackgroundScannerResponse.shared

Background Scanning #

Start Scanning beacons on background (Will only scan the beacons on both foreground/background/terminated states)

    snowmScanner.scanBeaconsBackground(uuids: uuids);

It will start background scanner and send a callback on native android and iOS platforms respectively

0.5.0+1 #

  • Background scanning issues fixed

0.5.0 #

  • Distance calculation improved

0.4.3+2 #

  • Changed the android behaviour to more logical one.

0.4.3 #

  • Changed the iOS behaviour to more logical one.

0.4.2+4 #

  • Network state added

0.4.2+3 #

  • Scanner callback on 0 beacons scanned

0.4.2+1 #

  • Fixed multi geofence issue

0.4.2 #

  • Supports multi geofencing on background scanner on ios

0.4.1 #

  • Supports multi geofencing on background scanner on Android

0.4.0+1 #

  • Added multi geo fencing support

0.4.0+1 #

  • Added better api exposure

0.4.0 #

  • Added Geofencing on background scanner as well as a seperate geo fencing function
  • Added support for background battery saving on android

0.3.1+4 #

  • Added parser

0.3.1+3 #

  • Added omre fix to geo fencing and other stuff

0.3.1+1 #

  • Fixed iOS syntax issue

0.3.1 #

  • Added geofencing support on iOS for background scanning

0.3.0+2 #

  • Opened the parameters of snowm beacon object on IOS

0.3.0+1 #

  • Added minor issue fixes.

0.3.0 #

  • Added background scanning support for iOS as well.

0.2.0+4 #

  • Fixes

0.2.0+3 #

  • Added stop background scan feature

0.2.0+1 #

  • Added doc about embedding v2 and fixed uuid uppercase issue

0.2.0 #

  • Background scanning done on andoird

0.1.0+1 #

  • Scan ibeacons on both android and iOS

0.1.0 #

  • Scan ibeacons on both android and iOS

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:snowm_scanner_example/screens/scanner.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ScannerScreen(),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  snowm_scanner: ^0.5.0+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:snowm_scanner/snowm_scanner.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
87
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:snowm_scanner/snowm_scanner.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:snowm_scanner/snowm_scanner.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:snowm_scanner/snowm_scanner.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:snowm_scanner/snowm_scanner.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [snowm_scanner] that is in a package requiring null.

Maintenance suggestions

The package description is too short. (-13 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test