Skip to content

Commit

Permalink
#8 Fixed the issue where the plugins were not yet registered
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Dec 23, 2020
1 parent 1b659f8 commit 40c9bdd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ios/Classes/BackgroundLocationTrackerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#endif

@implementation BackgroundLocationTrackerPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftBackgroundLocationTrackerPlugin registerWithRegistrar:registrar];
}

+ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback {
[SwiftBackgroundLocationTrackerPlugin setPluginRegistrantCallback:callback];
}

@end
3 changes: 1 addition & 2 deletions lib/src/background_location_tracker_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import 'package:background_location_tracker/src/model/background_location_update
import 'package:background_location_tracker/src/model/config/background_location_tracker_config.dart';
import 'package:background_location_tracker/src/util/logger.dart';

typedef LocationUpdateCallback = void Function(BackgroundLocationUpdateData data);
typedef LocationUpdateCallback = Future<void> Function(BackgroundLocationUpdateData data);

class BackgroundLocationTrackerManager {

static Future<void> initialize(Function callback, {BackgroundLocationTrackerConfig config}) {
final pluginConfig = config ??= const BackgroundLocationTrackerConfig();
BackgroundLocationTrackerLogger.enableLogging = pluginConfig.loggingEnabled;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/channel/background_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ class BackgroundChannel {
..setMethodCallHandler((call) async {
switch (call.method) {
case 'onLocationUpdate':
await handleLocationUpdate(call, callback, enableLogging: enableLogging);
break;
return handleLocationUpdate(call, callback, enableLogging: enableLogging);
default:
break;
return false;
}
})
..invokeMethod<void>(
'initialized',
);
}

static Future<void> handleLocationUpdate(MethodCall call, LocationUpdateCallback callback, {bool enableLogging = false}) async {
static Future<bool> handleLocationUpdate(MethodCall call, LocationUpdateCallback callback, {bool enableLogging = false}) async {
final data = call.arguments as Map<dynamic, dynamic>; // ignore: avoid_as
final isLoggingEnabled = data['logging_enabled'] as bool; // ignore: avoid_as
BackgroundLocationTrackerLogger.enableLogging = isLoggingEnabled;
BackgroundLocationTrackerLogger.log('locationUpdate: ${call.arguments}');
final lat = data['lat'] as double; // ignore: avoid_as
final lon = data['lon'] as double; // ignore: avoid_as
callback(BackgroundLocationUpdateData(lat: lat, lon: lon));
await callback(BackgroundLocationUpdateData(lat: lat, lon: lon));
return true;
}
}

0 comments on commit 40c9bdd

Please sign in to comment.