-
Notifications
You must be signed in to change notification settings - Fork 365
Use other plugins in callback
mehdi sohrabi edited this page Apr 11, 2020
·
4 revisions
The idea is to register the plugins manually.
- 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"))
}
}
}
- Register your Application class in manifest
<application
android:name=".Application"
- 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);
}