Skip to content

Commit

Permalink
Merge fcbf28d 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 + fcbf28d commit 6a9c28a
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 79 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
3 changes: 2 additions & 1 deletion .github/workflows/pub-publish-test.yaml
Expand Up @@ -21,13 +21,14 @@ 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: dartdoc --version
- run: make docs
- run: pub publish -n -v
3 changes: 2 additions & 1 deletion .github/workflows/pub-publish.yaml
Expand Up @@ -18,13 +18,14 @@ 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: dartdoc --version
- run: make docs
- run: 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
6 changes: 3 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
31 changes: 16 additions & 15 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,
}) : 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 @@ -76,7 +77,7 @@ class Beacon {
/// Parsing dynamic data into integer.
static int _parseInt(dynamic data) {
if (data is num) {
return data;
return data.toInt();
} else if (data is String) {
return int.tryParse(data) ?? 0;
}
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,7 +130,7 @@ class Beacon {
'proximityUUID': proximityUUID,
'major': major,
'minor': minor,
'rssi': rssi ?? -1,
'rssi': rssi,
'accuracy': accuracy,
'proximity': proximity.toString().split('.').last
};
Expand All @@ -152,7 +153,7 @@ class Beacon {
/// - `accuracy > 3.0` : [Proximity.far]
Proximity get proximity {
if (_proximity != null) {
return _proximity;
return _proximity!;
}

if (accuracy == 0.0) {
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
6 changes: 3 additions & 3 deletions lib/beacon/monitoring_result.dart
Expand Up @@ -22,7 +22,7 @@ class MonitoringResult {
/// The [MonitoringState] of monitoring result
///
/// This value is not null when [monitoringEventType] is [MonitoringEventType.didDetermineStateForRegion]
final MonitoringState monitoringState;
final MonitoringState? monitoringState;

/// The [Region] of ranging result.
final Region region;
Expand All @@ -34,7 +34,7 @@ class MonitoringResult {
this.region = Region.fromJson(json['region']);

/// Parsing dynamic state into [MonitoringState].
static MonitoringState _parseMonitoringState(dynamic state) {
static MonitoringState? _parseMonitoringState(dynamic state) {
if (!(state is String)) {
return null;
}
Expand All @@ -60,7 +60,7 @@ class MonitoringResult {
return MonitoringEventType.didDetermineStateForRegion;
}

return null;
throw Exception('invalid monitoring event type $event');
}

/// Return the serializable of this object into [Map].
Expand Down
10 changes: 5 additions & 5 deletions lib/beacon/region.dart
Expand Up @@ -12,23 +12,23 @@ class Region {
/// The proximity UUID of region.
///
/// For iOS, this value can not be null.
final String proximityUUID;
final String? proximityUUID;

/// The major number of region.
///
/// For both Android and iOS, this value can be null.
final int major;
final int? major;

/// The minor number of region.
///
/// For both Android and iOS, this value can be null.
final int minor;
final int? minor;

/// Constructor for creating [Region] object.
///
/// The [proximityUUID] must not be null when [Platform.isIOS]
Region({
@required this.identifier,
required this.identifier,
this.proximityUUID,
this.major,
this.minor,
Expand Down Expand Up @@ -81,7 +81,7 @@ class Region {
@override
int get hashCode => identifier.hashCode;

static int _parseMajorMinor(dynamic number) {
static int? _parseMajorMinor(dynamic number) {
if (number is int) {
return number;
}
Expand Down

0 comments on commit 6a9c28a

Please sign in to comment.