Skip to content

Commit

Permalink
Merge pull request #1 from pszklarska/master
Browse files Browse the repository at this point in the history
Pull From Source
  • Loading branch information
praveen-gm committed Jun 4, 2022
2 parents 2b8aeec + 4613f3f commit 0c9799d
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 44 deletions.
28 changes: 28 additions & 0 deletions .github/actions/pub-dev-publish/action.yml
@@ -0,0 +1,28 @@
name: 'Publish to pub.dev'
description: 'Action to publish (or perform a dry-run) to pub.dev'
inputs:
credentials:
required: true
dry_run:
required: false
default: true
runs:
using: "composite"
steps:
- env:
credentials: ${{ inputs.credentials }}
dry_run: ${{ inputs.dry_run }}
run: |
echo "Copying credentials..."
mkdir -p $HOME/.config/dart
echo "${credentials}" >> $HOME/.config/dart/pub-credentials.json
if "$dry_run"; then
echo "Running dry-run..."
flutter pub publish --dry-run
else
echo "Publishing the package..."
flutter pub publish -f
fi
rm $HOME/.config/dart/pub-credentials.json
shell: bash
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -57,12 +57,15 @@ jobs:
- name: Fetch sources
uses: actions/checkout@v2.3.4

# Install Flutter
- name: Install Flutter
uses: subosito/flutter-action@v1.5.3

# Run package publish dry-run
- name: Dry-run package publish
uses: sakebook/actions-flutter-pub-publisher@v1.3.1
uses: ./.github/actions/pub-dev-publish
with:
credential: ${{ secrets.CREDENTIALS_JSON }}
skip_test: true
credentials: ${{ secrets.CREDENTIALS_JSON }}
dry_run: true


Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Expand Up @@ -15,9 +15,14 @@ jobs:
with:
ref: ${{ github.event.release.tag_name }}

# Install Flutter
- name: Install Flutter
uses: subosito/flutter-action@v1.5.3

# Publish the plugin
- uses: actions/checkout@v1
- name: Publish
uses: sakebook/actions-flutter-pub-publisher@v1.3.1
uses: ./.github/actions/pub-dev-publish
with:
credential: ${{ secrets.CREDENTIALS_JSON }}
skip_test: true
credentials: ${{ secrets.CREDENTIALS_JSON }}
dry_run: false
22 changes: 15 additions & 7 deletions example/lib/main.dart
Expand Up @@ -30,13 +30,16 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
beaconBroadcast.checkTransmissionSupported().then((isTransmissionSupported) {
beaconBroadcast
.checkTransmissionSupported()
.then((isTransmissionSupported) {
setState(() {
_isTransmissionSupported = isTransmissionSupported;
});
});

_isAdvertisingSubscription = beaconBroadcast.getAdvertisingStateChange().listen((isAdvertising) {
_isAdvertisingSubscription =
beaconBroadcast.getAdvertisingStateChange().listen((isAdvertising) {
setState(() {
_isAdvertising = isAdvertising;
});
Expand All @@ -58,11 +61,15 @@ class _MyAppState extends State<MyApp> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Is transmission supported?', style: Theme.of(context).textTheme.headline5),
Text('$_isTransmissionSupported', style: Theme.of(context).textTheme.subtitle1),
Text('Is transmission supported?',
style: Theme.of(context).textTheme.headline5),
Text('$_isTransmissionSupported',
style: Theme.of(context).textTheme.subtitle1),
Container(height: 16.0),
Text('Has beacon started?', style: Theme.of(context).textTheme.headline5),
Text('$_isAdvertising', style: Theme.of(context).textTheme.subtitle1),
Text('Has beacon started?',
style: Theme.of(context).textTheme.headline5),
Text('$_isAdvertising',
style: Theme.of(context).textTheme.subtitle1),
Container(height: 16.0),
Center(
child: ElevatedButton(
Expand Down Expand Up @@ -90,7 +97,8 @@ class _MyAppState extends State<MyApp> {
child: Text('STOP'),
),
),
Text('Beacon Data', style: Theme.of(context).textTheme.headline5),
Text('Beacon Data',
style: Theme.of(context).textTheme.headline5),
Text('UUID: $uuid'),
Text('Major id: $majorId'),
Text('Minor id: $minorId'),
Expand Down
21 changes: 14 additions & 7 deletions example/pubspec.lock
Expand Up @@ -7,14 +7,14 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
beacon_broadcast:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "0.3.1"
version: "0.3.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -73,7 +73,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -134,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -148,7 +155,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.20.0"
43 changes: 29 additions & 14 deletions lib/beacon_broadcast.dart
Expand Up @@ -23,11 +23,16 @@ import 'dart:async';
import 'package:flutter/services.dart';

class BeaconBroadcast {
static const String ALTBEACON_LAYOUT = 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25';
static const String EDDYSTONE_TLM_LAYOUT = 'x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15';
static const String EDDYSTONE_UID_LAYOUT = 's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19';
static const String EDDYSTONE_URL_LAYOUT = 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v';
static const String URI_BEACON_LAYOUT = 's:0-1=fed8,m:2-2=00,p:3-3:-41,i:4-21v';
static const String ALTBEACON_LAYOUT =
'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25';
static const String EDDYSTONE_TLM_LAYOUT =
'x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15';
static const String EDDYSTONE_UID_LAYOUT =
's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19';
static const String EDDYSTONE_URL_LAYOUT =
's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v';
static const String URI_BEACON_LAYOUT =
's:0-1=fed8,m:2-2=00,p:3-3:-41,i:4-21v';

String? _uuid;
int? _majorId;
Expand All @@ -39,9 +44,11 @@ class BeaconBroadcast {
int? _manufacturerId;
List<int>? _extraData;

static const MethodChannel _methodChannel = const MethodChannel('pl.pszklarska.beaconbroadcast/beacon_state');
static const MethodChannel _methodChannel =
const MethodChannel('pl.pszklarska.beaconbroadcast/beacon_state');

static const EventChannel _eventChannel = const EventChannel('pl.pszklarska.beaconbroadcast/beacon_events');
static const EventChannel _eventChannel =
const EventChannel('pl.pszklarska.beaconbroadcast/beacon_events');

/// Sets UUID for beacon.
///
Expand Down Expand Up @@ -158,7 +165,8 @@ class BeaconBroadcast {
/// This parameter is optional.
BeaconBroadcast setExtraData(List<int> extraData) {
if (extraData.any((value) => value < 0 || value > 255)) {
throw new IllegalArgumentException("Illegal arguments! Extra data values must be within a byte range 0-255");
throw new IllegalArgumentException(
"Illegal arguments! Extra data values must be within a byte range 0-255");
}
_extraData = extraData;
return this;
Expand All @@ -179,11 +187,14 @@ class BeaconBroadcast {
/// quits the app, the system stops advertising the device as a peripheral over Bluetooth.
Future<void> start() async {
if (_uuid == null || _uuid!.isEmpty) {
throw new IllegalArgumentException("Illegal arguments! UUID must not be null or empty: UUID: $_uuid");
throw new IllegalArgumentException(
"Illegal arguments! UUID must not be null or empty: UUID: $_uuid");
}

if ((_layout == null || _layout == ALTBEACON_LAYOUT) && (_majorId == null || _minorId == null)) {
throw new IllegalArgumentException("Illegal arguments! MajorId and minorId must not be null or empty: "
if ((_layout == null || _layout == ALTBEACON_LAYOUT) &&
(_majorId == null || _minorId == null)) {
throw new IllegalArgumentException(
"Illegal arguments! MajorId and minorId must not be null or empty: "
"majorId: $_majorId, minorId: $_minorId");
}

Expand Down Expand Up @@ -229,7 +240,8 @@ class BeaconBroadcast {
/// * [BeaconStatus.notSupportedCannotGetAdvertiser] device does not have a compatible chipset
/// or driver
Future<BeaconStatus> checkTransmissionSupported() async {
var isTransmissionSupported = await _methodChannel.invokeMethod('isTransmissionSupported');
var isTransmissionSupported =
await _methodChannel.invokeMethod('isTransmissionSupported');
return _beaconStatusFromInt(isTransmissionSupported);
}
}
Expand Down Expand Up @@ -265,7 +277,8 @@ Map<int, BeaconStatus> _intToBeaconStatus = {
};

BeaconStatus _beaconStatusFromInt(int? value) {
if (!_intToBeaconStatus.containsKey(value)) return BeaconStatus.notSupportedCannotGetAdvertiser;
if (!_intToBeaconStatus.containsKey(value))
return BeaconStatus.notSupportedCannotGetAdvertiser;
return _intToBeaconStatus[value]!;
}

Expand All @@ -288,5 +301,7 @@ Map<int, AdvertiseMode> _intToAdvertiseMode = {

int? _advertiseModeToInt(AdvertiseMode advMode) {
if (!_intToAdvertiseMode.containsValue(advMode)) return null;
return _intToAdvertiseMode.entries.firstWhere((element) => element.value == advMode).key;
return _intToAdvertiseMode.entries
.firstWhere((element) => element.value == advMode)
.key;
}
36 changes: 26 additions & 10 deletions test/beacon_broadcast_test.dart
Expand Up @@ -97,14 +97,23 @@ void main() {
throwsA(isA<IllegalArgumentException>()));
});

test('when identifier and transmission power are not set starts normally', () async {
test('when identifier and transmission power are not set starts normally',
() async {
onStartMethodReturn(Future.value());
expect(() => BeaconBroadcast().setUUID("uuid").setMajorId(1).setMinorId(1).start(), returnsNormally);
expect(
() => BeaconBroadcast()
.setUUID("uuid")
.setMajorId(1)
.setMinorId(1)
.start(),
returnsNormally);
});

test('when extra data contains integer out of range throws exception', () async {
test('when extra data contains integer out of range throws exception',
() async {
onStartMethodReturn(Future.value());
expect(() => BeaconBroadcast().setUUID("uuid").setExtraData([270]).start(),
expect(
() => BeaconBroadcast().setUUID("uuid").setExtraData([270]).start(),
throwsA(isA<IllegalArgumentException>()));
});

Expand Down Expand Up @@ -152,22 +161,29 @@ void main() {
group('checking if transmission is supported', () {
test('when device returns 0 return BeaconStatus.supported', () async {
onIsTransmissionSupportedMethodReturn(Future.value(0));
expect(await BeaconBroadcast().checkTransmissionSupported(), BeaconStatus.supported);
expect(await BeaconBroadcast().checkTransmissionSupported(),
BeaconStatus.supported);
});

test('when device returns 1 return BeaconStatus.notSupportedMinSdk', () async {
test('when device returns 1 return BeaconStatus.notSupportedMinSdk',
() async {
onIsTransmissionSupportedMethodReturn(Future.value(1));
expect(await BeaconBroadcast().checkTransmissionSupported(), BeaconStatus.notSupportedMinSdk);
expect(await BeaconBroadcast().checkTransmissionSupported(),
BeaconStatus.notSupportedMinSdk);
});

test('when device returns 2 return BeaconStatus.notSupportedBle', () async {
onIsTransmissionSupportedMethodReturn(Future.value(2));
expect(await BeaconBroadcast().checkTransmissionSupported(), BeaconStatus.notSupportedBle);
expect(await BeaconBroadcast().checkTransmissionSupported(),
BeaconStatus.notSupportedBle);
});

test('when device returns other value return BeaconStatus.notSupportedCannotGetAdvertiser', () async {
test(
'when device returns other value return BeaconStatus.notSupportedCannotGetAdvertiser',
() async {
onIsTransmissionSupportedMethodReturn(Future.value(3));
expect(await BeaconBroadcast().checkTransmissionSupported(), BeaconStatus.notSupportedCannotGetAdvertiser);
expect(await BeaconBroadcast().checkTransmissionSupported(),
BeaconStatus.notSupportedCannotGetAdvertiser);
});
});

Expand Down

0 comments on commit 0c9799d

Please sign in to comment.