apptreesoftware / flutter_webview

An embeddable webView plugin for flutter.
MIT License
113 stars 31 forks source link

registrar.activity() returns null when used with Flutter's background execution feature. #31

Open xsahil03x opened 4 years ago

xsahil03x commented 4 years ago

Flutter's new background execution feature (described here: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124) allows plugins to be registered in a background context (e.g. a Service). The problem is that the flutter_webview plugin assumes that the context for plugin registration is an activity with this line of code:

val plugin = FlutterWebViewPlugin(registrar.activity())

registrar.activity() may now return null, and this leads to a NullPointerException:

The solution is to change the above line of code to this:

val plugin = FlutterWebViewPlugin(registrar.activeContext())

rlee1990 commented 4 years ago

This is needed as must plugins no longer need class MainActivity: FlutterActivity() { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); } }

and will not run with it and this plugin won't run without it.