initAndroidListener method
void
initAndroidListener()
Implementation
void initAndroidListener() {
if (Platform.isAndroid) {
// 电子围栏回调
MethodChannel(
'com.amap.api.fence.GeoFenceClient::addGeoFenceX::Callback',
kAmapLocationFluttifyMethodCodec,
).setMethodCallHandler((call) async {
if (call.method ==
'Callback::com.amap.api.fence.GeoFenceClient::addGeoFenceX') {
final args = await call.arguments as Map;
final status = args['status'] as int;
final customId = args['customId'] as String;
final fenceId = args['fenceId'] as String;
debugPrint(
'收到围栏消息: status: $status, customId: $customId, fenceId:$fenceId');
final fence = com_amap_api_fence_GeoFence()
..refId = (args['fence'] as Ref).refId;
_geoFenceEventController?.add(
GeoFenceEvent(
customId: customId,
fenceId: fenceId,
status: GeoFenceStatusX.fromAndroid(status),
genFence: GeoFence.android(fence),
),
);
}
});
}
}