blue_print_pos icon indicating copy to clipboard operation
blue_print_pos copied to clipboard

build error in FLNativeViewFactory

Open flutter-painter opened this issue 2 years ago • 4 comments

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)

flutter-painter avatar Jun 13 '22 21:06 flutter-painter

linked with https://github.com/flutter/flutter/issues/104480 @andriyoganp are you able to apply the fix suggested by ilber ?

flutter-painter avatar Jun 24 '22 17:06 flutter-painter

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!

marcchiu avatar Jun 27 '22 08:06 marcchiu

huycozy fixes is better model fixed in https://github.com/andriyoganp/blue_print_pos/pull/67

flutter-painter avatar Jun 28 '22 23:06 flutter-painter

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

janith-jware avatar Nov 28 '22 04:11 janith-jware