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

Error when compiling - Kotlin language related #40

Open
d-apps opened this issue Mar 2, 2021 · 0 comments
Open

Error when compiling - Kotlin language related #40

d-apps opened this issue Mar 2, 2021 · 0 comments

Comments

@d-apps
Copy link

d-apps commented Mar 2, 2021

When I try to run the project I have this error:

e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_pdf_viewer-0.6.1\android\src\main\kotlin\com\pycampers\flutterpdfviewer\PdfActivityThread.kt: (82, 47): The spread operator (*foo) may not be applied to an argument of nullable type

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_pdf_viewer:compileDebugKotlin'.
> Compilation error. See log for more details

The error is on: configurator = configurator.pages(*opts.getIntArray("pages"))

I already tried to remove the "*" but it gives me another error:

Type mismatch: inferred type is IntArray? but Int was expected

PdfActivityThread.kt

package com.pycampers.flutterpdfviewer

import android.os.Bundle
import android.util.Log
import android.view.View
import com.github.barteksc.pdfviewer.PDFView
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
import java.io.File

// This thread is used to do heavy tasks, like loading the PDF from disk, decrypting it etc.
class PdfActivityThread(
    val activity: PdfActivity,
    val opts: Bundle,
    val pdfView: PDFView,
    val playerController: PlayerController,
    val scrollHandle: DefaultScrollHandle,
    val initialPage: Int
) : Thread() {
    val mode = opts.getString("mode")!!
    val xorDecryptKey: String? = opts.getString("xorDecryptKey")

    fun buildConfigurator(): PDFView.Configurator? {
        val src = opts.getString("src")!!

        xorDecryptKey?.let {
            val bytes = when (mode) {
                "fromFile" -> {
                    Log.d(TAG, "loading encrypted pdf from file { $src }...")
                    readBytesFromFile(src)
                }
                "fromBytes" -> {
                    Log.d(TAG, "loading encrypted pdf from bytes...")
                    readBytesFromSocket(src)
                }
                "fromAsset" -> {
                    Log.d(TAG, "loading encrypted pdf from assets { $src }...")
                    readBytesFromAsset(activity.applicationContext, src)
                }
                else -> throw IllegalArgumentException("invalid mode: $mode.")
            }
            xorEncryptDecrypt(bytes, it)
            return pdfView.fromBytes(bytes)
        }

        return when (mode) {
            "fromFile" -> {
                Log.d(TAG, "loading pdf from file { $src }...")
                pdfView.fromFile(File(src))
            }
            "fromBytes" -> {
                Log.d(TAG, "loading pdf from bytes...")
                pdfView.fromBytes(readBytesFromSocket(src))
            }
            "fromAsset" -> {
                Log.d(TAG, "loading pdf from assets { $src }...")
                pdfView.fromAsset(src)
            }
            else -> throw IllegalArgumentException("invalid mode: $mode.")
        }
    }

    override fun run() {
        pdfView.visibility = View.VISIBLE
        var configurator = buildConfigurator()!!

        configurator = configurator
            .password(opts.getString("password"))
            .nightMode(opts.getBoolean("nightMode"))
            .enableSwipe(opts.getBoolean("enableSwipe"))
            .swipeHorizontal(opts.getBoolean("swipeHorizontal"))
            .autoSpacing(opts.getBoolean("autoSpacing"))
            .pageFling(opts.getBoolean("pageFling"))
            .pageSnap(opts.getBoolean("pageSnap"))
            .onError(activity)
            .onRender(activity)
            .scrollHandle(scrollHandle)
            .onPageChange(playerController)
            .onTap(playerController)
            .defaultPage(initialPage)

        if (opts.containsKey("pages")) {
            configurator = configurator.pages(*opts.getIntArray("pages"))
        }

        configurator.load()
    }
}
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

1 participant