2

I am a beginner in Flutter. I am working on a Geofencing feature. Whenever a user enters/exits the geofence region, a local notification should get fired. Here is the code I am using

ReceivePort port = ReceivePort();

@pragma('vm:entry-point')
@override
void initState() {
super.initState();
IsolateNameServer.registerPortWithName(
  port.sendPort,
  'send_port',
);
port.listen((dynamic data) {
// Fire a Local notification 
});
}

@pragma('vm:entry-point')
static void callback(List<String> ids, Location location) async {
final SendPort? sendport =
     IsolateNameServer.lookupPortByName('send_port');
sendport?.send([ids[0].toString(), location.toString()]);
}

callback function gets called whenever a user enters/exits the region.

This code works fine on iOS. If a user has entered/exited the region, the user gets a local notification even if the app is in terminated state.

On Android it works well when the app is in foreground or background mode. But when the app is in terminated state(not running state) it does not work.

The problem is IsolateNameServer.lookupPortByName('send_port') returns null.

final SendPort? sendport = IsolateNameServer.lookupPortByName('send_port');

works well on iOS but it return null on Android.

Yakshita
  • 21
  • 2

0 Answers0