Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alann-maulana committed Apr 26, 2021
1 parent 3db2e5a commit e278e83
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
12 changes: 12 additions & 0 deletions lib/beacon/authorization_status.dart
Original file line number Diff line number Diff line change
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
19 changes: 11 additions & 8 deletions lib/beacon/beacon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Beacon {
this.txPower,
required this.accuracy,
Proximity? proximity,
}) : rssi = rssi ?? -1,
}) : this.rssi = rssi ?? -1,
this._proximity = proximity;

/// Create beacon object from json.
Expand Down Expand Up @@ -75,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.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 @@ -135,9 +135,12 @@ class Beacon {
'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 Down Expand Up @@ -179,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
4 changes: 0 additions & 4 deletions lib/beacon/region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class Region {
int get hashCode => identifier.hashCode;

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

if (number is num) {
return number.toInt();
}
Expand Down
28 changes: 7 additions & 21 deletions lib/flutter_beacon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Set the default AuthorizationStatus to use in requesting location authorization.
Expand Down Expand Up @@ -116,11 +114,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Check for the latest [BluetoothState] from device.
Expand All @@ -138,11 +134,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Request to open Bluetooth Settings from device.
Expand All @@ -153,11 +147,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Request to open Locations Settings from device.
Expand All @@ -168,11 +160,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Request to open Application Settings from device.
Expand All @@ -183,11 +173,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Close scanning API.
Expand All @@ -196,11 +184,9 @@ class FlutterBeacon {

if (result is bool) {
return result;
} else if (result is int) {
return result == 1;
}

return result;
return result == 1;
}

/// Start ranging iBeacons with defined [List] of [Region]s.
Expand Down

0 comments on commit e278e83

Please sign in to comment.