beacon_broadcast 0.0.1 beacon_broadcast: ^0.0.1 copied to clipboard
A Flutter plugin for turning your device into a beacon.
import 'dart:async';
import 'package:beacon_broadcast/beacon_broadcast.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
BeaconBroadcast beaconBroadcast = BeaconBroadcast();
bool _isAdvertising = false;
StreamSubscription<bool> _isAdvertisingSubscription;
@override
void initState() {
super.initState();
_isAdvertisingSubscription =
beaconBroadcast.getAdvertisingStateChange().listen((isAdvertising) {
setState(() {
_isAdvertising = isAdvertising;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RaisedButton(
onPressed: () {
beaconBroadcast
.setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
.setMajorId(1)
.setMinorId(100)
.setTransmissionPower(-59)
.setIdentifier("com.example.myDeviceRegion")
.start();
},
child: Text('START'),
),
RaisedButton(
onPressed: () {
beaconBroadcast.stop();
},
child: Text('STOP'),
),
Text('Current state: $_isAdvertising')
],
),
),
),
);
}
@override
void dispose() {
super.dispose();
if (_isAdvertisingSubscription != null) {
_isAdvertisingSubscription.cancel();
}
}
}