callbackDispatcher function
void
callbackDispatcher()
Implementation
void callbackDispatcher() {
// 1. Initialize MethodChannel used to communicate with the platform portion of the plugin.
const MethodChannel _backgroundChannel = MethodChannel('android_location_background');
// 2. Setup internal state needed for MethodChannels.
WidgetsFlutterBinding.ensureInitialized();
// 3. Listen for background events from the platform portion of the plugin.
_backgroundChannel.setMethodCallHandler((MethodCall call) async {
final args = call.arguments;
print('Received callback invocation with arguments:');
print('\n');
print(args);
// 3.1. Retrieve callback instance for handle.
final Function callback = PluginUtilities.getCallbackFromHandle(CallbackHandle.fromRawHandle(args[0]));
//assert(callback != null);
if (callback == null) {
print('Callback is null');
} else {
print('Callback is not null');
try {
// 3.2. Preprocess arguments.
final coordinates = args[1];
print(coordinates);
// 3.3. Invoke callback.
callback(coordinates);
} catch(Exception) {
print(Exception);
}
}
});
// 4. Alert plugin that the callback handler is ready for events.
_backgroundChannel.invokeMethod('initialized');
}