Skip to content

Commit

Permalink
Make functions more generic, add tests, reformat code.
Browse files Browse the repository at this point in the history
  • Loading branch information
paolorotolo committed May 6, 2021
1 parent 40eb866 commit cd5266a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ios/Classes/FlutterBeaconPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
result(@(YES));
return;
}

if ([@"setScanPeriod" isEqualToString:call.method]) {
// do nothing

result(@(YES));
return;
}

if ([@"setBetweenScanPeriod" isEqualToString:call.method]) {
// do nothing

result(@(YES));
return;
}

if ([@"openApplicationSettings" isEqualToString:call.method]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Expand Down
9 changes: 4 additions & 5 deletions lib/flutter_beacon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class FlutterBeacon {
/// This information does not change from call to call. Cache it.
Stream<AuthorizationStatus>? _onAuthorizationStatus;


/// Initialize scanning API.
Future<bool> get initializeScanning async {
final result = await _methodChannel.invokeMethod('initialize');
Expand Down Expand Up @@ -180,15 +179,15 @@ class FlutterBeacon {
}

/// Customize duration of the beacon scan on the Android Platform.
Future<bool> setAndroidScanPeriod(int scanPeriod) async {
Future<bool> setScanPeriod(int scanPeriod) async {
return await _methodChannel
.invokeMethod('setScanPeriod', {"scanPeriod": scanPeriod});
}

/// Customize duration spent not scanning between each scan cycle on the Android Platform.
Future<bool> setAndroidBetweenScanPeriod(int scanPeriod) async {
return await _methodChannel
.invokeMethod('setBetweenScanPeriod', {"betweenScanPeriod": scanPeriod});
Future<bool> setBetweenScanPeriod(int scanPeriod) async {
return await _methodChannel.invokeMethod(
'setBetweenScanPeriod', {"betweenScanPeriod": scanPeriod});
}

/// Close scanning API.
Expand Down
22 changes: 22 additions & 0 deletions test/flutter_beacon_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ void main() {
return true;
}

if (method == 'setScanPeriod') {
return true;
}

if (method == 'setBetweenScanPeriod') {
return true;
}

throw MissingPluginException(
'No implementation found for method $method on channel ${channel.name}');
});
Expand Down Expand Up @@ -263,6 +271,20 @@ void main() {
true,
);
});

test('SetScanPeriod return "true"', () async {
expect(
await flutterBeacon.setScanPeriod(1000),
true,
);
});

test('SetBetweenScanPeriod return "true"', () async {
expect(
await flutterBeacon.setBetweenScanPeriod(400),
true,
);
});
});

group('Event channel - ranging', () {
Expand Down

0 comments on commit cd5266a

Please sign in to comment.