Skip to content

Use other plugins in callback

mehdi sohrabi edited this page Apr 11, 2020 · 4 revisions

Use other plugins in callback

By Marcelo Henrique Neppel.

The idea is to register the plugins manually.

  1. Create Application file for your android project
class Application : FlutterApplication(), PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        LocatorService.setPluginRegistrant(this)
        FlutterMain.startInitialization(this)
    }
    
    override fun registerWith(registry: PluginRegistry?) {
        if (!registry!!.hasPlugin("io.flutter.plugins.pathprovider")) {
            PathProviderPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.pathprovider"))
        }
    }
}
  1. Register your Application class in manifest
<application
        android:name=".Application"
  1. Now you can use this plugin in you main dart code:
static void callback(LocationDto locationDto) async {
  print('location in dart: ${locationDto.toString()}');
  final SendPort send = IsolateNameServer.lookupPortByName(_isolateName);
  send?.send(locationDto);
  //the '?' check if send is null before executing it

  final file = await _getTempLogFile();
  await file.writeAsString(locationDto.toString(), mode: FileMode.append);
}
Clone this wiki locally