blue_print_pos
blue_print_pos copied to clipboard
build error in FLNativeViewFactory
Since upgrading flutter I run across this error when trying to build
blue_print_pos/FLNativeViewFactory.kt: (10, 1): Class 'FLNativeViewFactory' is not abstract and does not implement abstract base class member public abstract fun create(p0: Context?, p1: Int, p2: Any?): PlatformView defined in io.flutter.plugin.platform.PlatformViewFactory
[✓] Flutter (Channel stable, 3.0.2, on macOS 11.4 20F71 darwin-x64, locale en-GB) [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.67.2)
linked with https://github.com/flutter/flutter/issues/104480 @andriyoganp are you able to apply the fix suggested by ilber ?
Same problem here, I have read through the fix by ilber too but got no idea how to work on it. Sorry I don't really know Kotlin. Please help!
huycozy fixes is better model fixed in https://github.com/andriyoganp/blue_print_pos/pull/67
I made the following changes to blue_print_pos/FLNativeViewFactory.kt. Build was successful.
From this:
class FLNativeViewFactory : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
val creationParams = args as Map<String?, Any?>?
return FLNativeView(context, viewId, creationParams)
}
}
internal class FLNativeView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView {
private val webView: WebView = WebView(context)
private var arguments: Map<String?, Any?>? = creationParams
override fun getView(): View {
return webView
}
override fun dispose() {}
init {
var width = (arguments!!["width"]!! as Number).toInt()
var height = (arguments!!["height"]!! as Number).toInt()
var content = arguments!!["content"] as String
webView.layout(0, 0, width, height)
webView.loadDataWithBaseURL(null, content, "text/HTML", "UTF-8", null)
webView.setInitialScale(1)
webView.settings.javaScriptEnabled = true
webView.settings.useWideViewPort = true
webView.settings.javaScriptCanOpenWindowsAutomatically = true
webView.settings.loadWithOverviewMode = true
}
}
To this:
class FLNativeViewFactory : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
override fun create(context: Context?, viewId: Int, args: Any?): PlatformView {
val creationParams = args as Map<String?, Any?>?
return FLNativeView(context!!, viewId, creationParams)
}
}
internal class FLNativeView(context: Context?, id: Int, creationParams: Map<String?, Any?>?) : PlatformView {
private val webView: WebView = WebView(context!!)
private var arguments: Map<String?, Any?>? = creationParams
override fun getView(): View {
return webView
}
override fun dispose() {}
init {
var width = (arguments!!["width"]!! as Number).toInt()
var height = (arguments!!["height"]!! as Number).toInt()
var content = arguments!!["content"] as String
webView.layout(0, 0, width, height)
webView.loadDataWithBaseURL(null, content, "text/HTML", "UTF-8", null)
webView.setInitialScale(1)
webView.settings.javaScriptEnabled = true
webView.settings.useWideViewPort = true
webView.settings.javaScriptCanOpenWindowsAutomatically = true
webView.settings.loadWithOverviewMode = true
}
}
It's error from null safety of kotlin.
I added ?
to context:Context
and added !!
to context