Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build error in FLNativeViewFactory #65

Open
flutter-painter opened this issue Jun 13, 2022 · 4 comments
Open

build error in FLNativeViewFactory #65

flutter-painter opened this issue Jun 13, 2022 · 4 comments

Comments

@flutter-painter
Copy link

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
Copy link
Author

linked with flutter/flutter#104480
@andriyoganp are you able to apply the fix suggested by ilber ?

@marcchiu
Copy link

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!

@flutter-painter
Copy link
Author

flutter-painter commented Jun 28, 2022

huycozy fixes is better model
fixed in #67

@janith-jware
Copy link

janith-jware commented Nov 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants