Search code examples
androidflutterkotlinbackground-processflutter-dependencies

How can I run dart code in the background in flutter?


I want to run a method in my main.dart file from the android(Kotlin) part of my app. For this I am using methodChannels and it works perfectly fine when the app is in foreground. However, the moment the app is killed, the flutterView is destroyed and therefore I am unable to run any methods in my main.dart file.

I read that using FlutterNativeView would allow me to do what I want but I am unable to find small code snippets to help me with it.

It would be great if you could help me with this

Thanks!!


Solution

  • You can write the native code for Firebase realtime database. You can check this.

    You should create a custom plugin and put the native code in that plugin as writing the files directly in the Flutter android folder will make the project unmanageable in the future and you can face multiple unexpected issues.