Skip to content

Conversation

@jonathanduke
Copy link

Fixes #645

Cause

The SharedPrefs value for the dispatcher handle is set during initialize, but the local currentDispatcherHandle variable was not updated.

Fix

override fun initialize(
    request: InitializeRequest,
    callback: (Result<Unit>) -> Unit,
) {
    try {
        // get the handle first
        val handle = request.callbackHandle

        // make sure it's not invalid
        if (handle <= 0L) {
            callback(Result.failure(Exception(INIT_FAILED)))
            return
        }

        // store in SharedPrefs as before
        preferenceManager.saveCallbackDispatcherHandleKey(handle)

        // additionally, set the local variable to match
        currentDispatcherHandle = handle

        // continue as before
        callback(Result.success(Unit))
    } catch (e: Exception) {
        callback(Result.failure(e))
    }
}

@docs-page
Copy link

docs-page bot commented Aug 26, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~646

Documentation is deployed and generated using docs.page.

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

Successfully merging this pull request may close these issues.

🐞PlatformException "You have not properly initialized the Flutter WorkManager Package" on first run

1 participant