Skip to content

Commit

Permalink
Merge 4f47bfa into ad4ab04
Browse files Browse the repository at this point in the history
  • Loading branch information
alann-maulana committed Apr 26, 2021
2 parents ad4ab04 + 4f47bfa commit ea4bee8
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage-report.yaml
Expand Up @@ -21,7 +21,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.22.4'
flutter-version: '2.0.5'
channel: 'stable'
- name: Generate coverage report
run: flutter test --coverage --coverage-path ./coverage/lcov.info
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yaml
Expand Up @@ -22,7 +22,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.22.4'
flutter-version: '2.0.5'
channel: 'stable'
- run: flutter packages get
- run: flutter format --set-exit-if-changed .
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/pub-publish-test.yaml
Expand Up @@ -21,13 +21,15 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.22.4'
flutter-version: '2.0.5'
channel: 'stable'
- run: echo "FLUTTER_ROOT=$FLUTTER_HOME" >> $GITHUB_ENV && echo $FLUTTER_ROOT
- run: bash scripts/credentials.sh
- run: rm -rf scripts/
- run: make
- run: make deps
- run: pub global activate dartdoc
- run: make docs
- run: pub publish -n -v
- name: Documenting package
run: |
echo "FLUTTER_ROOT=$FLUTTER_HOME" >> $GITHUB_ENV
bash scripts/credentials.sh
rm -rf scripts/
make
make deps
pub global activate dartdoc
make docs
pub publish -n -v
20 changes: 11 additions & 9 deletions .github/workflows/pub-publish.yaml
Expand Up @@ -18,13 +18,15 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.22.4'
flutter-version: '2.0.5'
channel: 'stable'
- run: echo "FLUTTER_ROOT=$FLUTTER_HOME" >> $GITHUB_ENV && echo $FLUTTER_ROOT
- run: bash scripts/credentials.sh
- run: rm -rf scripts/
- run: make
- run: make deps
- run: pub global activate dartdoc
- run: make docs
- run: pub publish -f -v
- name: Documenting package
run: |
echo "FLUTTER_ROOT=$FLUTTER_HOME" >> $GITHUB_ENV
bash scripts/credentials.sh
rm -rf scripts/
make
make deps
pub global activate dartdoc
make docs
pub publish -f -v
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -22,7 +22,7 @@ pana:

docs:
rm -rf doc
dartdoc --exclude 'dart:async,dart:collection,dart:convert,dart:core,dart:developer,dart:io,dart:isolate,dart:math,dart:typed_data,dart:ui,dart:html_common,dart:ffi,dart:html,dart:js,dart:js_util' --ignore 'ambiguous-doc-reference'
pub global run dartdoc --exclude 'dart:async,dart:collection,dart:convert,dart:core,dart:developer,dart:io,dart:isolate,dart:math,dart:typed_data,dart:ui,dart:html_common,dart:ffi,dart:html,dart:js,dart:js_util' --ignore 'ambiguous-doc-reference' --sdk-dir '${FLUTTER_ROOT}/bin/cache/dart-sdk'

publish:
pub publish
5 changes: 2 additions & 3 deletions example/lib/main.dart
@@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_beacon_example/controller/requirement_state_controller.dart';
import 'package:flutter_beacon_example/view/home_page.dart';
import 'package:get/get.dart';

import 'controller/requirement_state_controller.dart';
import 'view/home_page.dart';

void main() {
runApp(MainApp());
}
Expand Down
15 changes: 12 additions & 3 deletions example/lib/view/app_broadcasting.dart
Expand Up @@ -158,7 +158,18 @@ class _TabBroadcastingState extends State<TabBroadcasting> {
}

Widget get buttonBroadcast {
return RaisedButton(
final ButtonStyle raisedButtonStyle = ElevatedButton.styleFrom(
onPrimary: Colors.white,
primary: broadcasting ? Colors.red : Theme.of(context).primaryColor,
minimumSize: Size(88, 36),
padding: EdgeInsets.symmetric(horizontal: 16),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
),
);

return ElevatedButton(
style: raisedButtonStyle,
onPressed: () async {
if (broadcasting) {
await flutterBeacon.stopBroadcast();
Expand All @@ -179,8 +190,6 @@ class _TabBroadcastingState extends State<TabBroadcasting> {
}
},
child: Text('Broadcast${broadcasting ? 'ing' : ''}'),
color: broadcasting ? Colors.red : Theme.of(context).primaryColor,
textColor: Colors.white,
);
}
}
3 changes: 1 addition & 2 deletions example/lib/view/app_scanning.dart
Expand Up @@ -2,10 +2,9 @@ import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_beacon/flutter_beacon.dart';
import 'package:flutter_beacon_example/controller/requirement_state_controller.dart';
import 'package:get/get.dart';

import '../controller/requirement_state_controller.dart';

class TabScanning extends StatefulWidget {
@override
_TabScanningState createState() => _TabScanningState();
Expand Down
11 changes: 5 additions & 6 deletions example/lib/view/home_page.dart
Expand Up @@ -4,12 +4,11 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_beacon/flutter_beacon.dart';
import 'package:flutter_beacon_example/controller/requirement_state_controller.dart';
import 'package:flutter_beacon_example/view/app_broadcasting.dart';
import 'package:flutter_beacon_example/view/app_scanning.dart';
import 'package:get/get.dart';

import 'app_scanning.dart';
import 'app_broadcasting.dart';
import '../controller/requirement_state_controller.dart';

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
Expand Down Expand Up @@ -220,7 +219,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
'Please enable Location Services on Settings > Privacy > Location Services.',
),
actions: [
FlatButton(
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('OK'),
),
Expand All @@ -246,7 +245,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: Text('Bluetooth is Off'),
content: Text('Please enable Bluetooth on Settings > Bluetooth.'),
actions: [
FlatButton(
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('OK'),
),
Expand Down
18 changes: 15 additions & 3 deletions lib/beacon/authorization_status.dart
Expand Up @@ -18,8 +18,8 @@ class AuthorizationStatus {
@visibleForTesting
const AuthorizationStatus.init(
this.value, {
this.isAndroid,
this.isIOS,
this.isAndroid = false,
this.isIOS = false,
});

@visibleForTesting
Expand All @@ -39,7 +39,7 @@ class AuthorizationStatus {
return notDetermined;
}

return null;
throw Exception('invalid authorization status $value');
}

/// Shows that user allowed the authorization.
Expand Down Expand Up @@ -93,6 +93,18 @@ class AuthorizationStatus {
isIOS: true,
);

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AuthorizationStatus &&
runtimeType == other.runtimeType &&
value == other.value &&
isAndroid == other.isAndroid &&
isIOS == other.isIOS;

@override
int get hashCode => value.hashCode ^ isAndroid.hashCode ^ isIOS.hashCode;

@override
String toString() {
return value;
Expand Down
48 changes: 26 additions & 22 deletions lib/beacon/beacon.dart
Expand Up @@ -15,7 +15,7 @@ class Beacon {
/// The mac address of beacon.
///
/// From iOS this value will be null
final String macAddress;
final String? macAddress;

/// The major value of beacon.
final int major;
Expand All @@ -29,25 +29,26 @@ class Beacon {
/// The transmission power of beacon.
///
/// From iOS this value will be null
final int txPower;
final int? txPower;

/// The accuracy of distance of beacon in meter.
final double accuracy;

/// The proximity of beacon.
final Proximity _proximity;
final Proximity? _proximity;

/// Create beacon object.
const Beacon({
this.proximityUUID,
required this.proximityUUID,
this.macAddress,
this.major,
this.minor,
this.rssi,
required this.major,
required this.minor,
int? rssi,
this.txPower,
this.accuracy,
Proximity proximity,
}) : this._proximity = proximity;
required this.accuracy,
Proximity? proximity,
}) : this.rssi = rssi ?? -1,
this._proximity = proximity;

/// Create beacon object from json.
Beacon.fromJson(dynamic json)
Expand All @@ -65,7 +66,7 @@ class Beacon {
/// Parsing dynamic data into double.
static double _parseDouble(dynamic data) {
if (data is num) {
return data;
return data.toDouble();
} else if (data is String) {
return double.tryParse(data) ?? 0.0;
}
Expand All @@ -74,14 +75,14 @@ class Beacon {
}

/// Parsing dynamic data into integer.
static int _parseInt(dynamic data) {
static int? _parseInt(dynamic data) {
if (data is num) {
return data;
return data.toInt();
} else if (data is String) {
return int.tryParse(data) ?? 0;
}

return 0;
return null;
}

/// Parsing dynamic proximity into enum [Proximity].
Expand Down Expand Up @@ -113,7 +114,7 @@ class Beacon {
}).toList();
}

return null;
return [];
}

/// Parsing [List] of [Beacon] into array of [Map].
Expand All @@ -129,14 +130,17 @@ class Beacon {
'proximityUUID': proximityUUID,
'major': major,
'minor': minor,
'rssi': rssi ?? -1,
'rssi': rssi,
'accuracy': accuracy,
'proximity': proximity.toString().split('.').last
};

if (Platform.isAndroid) {
map['txPower'] = txPower ?? -1;
map['macAddress'] = macAddress ?? "";
if (txPower != null) {
map['txPower'] = txPower;
}

if (macAddress != null) {
map['macAddress'] = macAddress;
}

return map;
Expand All @@ -152,7 +156,7 @@ class Beacon {
/// - `accuracy > 3.0` : [Proximity.far]
Proximity get proximity {
if (_proximity != null) {
return _proximity;
return _proximity!;
}

if (accuracy == 0.0) {
Expand All @@ -178,12 +182,12 @@ class Beacon {
proximityUUID == other.proximityUUID &&
major == other.major &&
minor == other.minor &&
(Platform.isAndroid ? macAddress == other.macAddress : true);
(macAddress != null ? macAddress == other.macAddress : true);

@override
int get hashCode {
int hashCode = proximityUUID.hashCode ^ major.hashCode ^ minor.hashCode;
if (Platform.isAndroid) {
if (macAddress != null) {
hashCode = hashCode ^ macAddress.hashCode;
}

Expand Down
31 changes: 18 additions & 13 deletions lib/beacon/beacon_broadcast.dart
Expand Up @@ -7,7 +7,7 @@ part of flutter_beacon;
/// Class for managing Beacon Broadcast object.
class BeaconBroadcast {
/// The unique identifier of region.
final String identifier;
final String? identifier;

/// The proximity UUID of beacon.
final String proximityUUID;
Expand All @@ -18,18 +18,18 @@ class BeaconBroadcast {
/// The minor value of beacon.
final int minor;

/// The minor value of beacon.
final int txPower;
/// The txPower value of beacon. Specify null to use the default value for the device.
final int? txPower;

final AdvertisingMode advertisingMode;
final AdvertisingMode? advertisingMode;

final AdvertisingTxPowerLevel advertisingTxPowerLevel;
final AdvertisingTxPowerLevel? advertisingTxPowerLevel;

BeaconBroadcast({
this.identifier = 'com.flutterBeacon',
@required this.proximityUUID,
@required this.major,
@required this.minor,
required this.proximityUUID,
required this.major,
required this.minor,
this.txPower,
this.advertisingMode = AdvertisingMode.low,
this.advertisingTxPowerLevel = AdvertisingTxPowerLevel.high,
Expand All @@ -51,11 +51,16 @@ class BeaconBroadcast {
'txPower': txPower,
};

if (Platform.isAndroid) {
map['advertisingMode'] = advertisingMode.index;
map['advertisingTxPowerLevel'] = advertisingTxPowerLevel.index;
} else if (Platform.isIOS) {
map['identifier'] = identifier;
if (advertisingMode != null) {
map['advertisingMode'] = advertisingMode!.index;
}

if (advertisingTxPowerLevel != null) {
map['advertisingTxPowerLevel'] = advertisingTxPowerLevel!.index;
}

if (identifier != null) {
map['identifier'] = identifier!;
}

return map;
Expand Down

0 comments on commit ea4bee8

Please sign in to comment.