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

fix error LateInitializationError: Local 'cancelFunc' has not been initialized #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nahrawene-ben-hmida
Copy link

The error LateInitializationError: Local 'cancelFunc' has not been initialized occurs because the cancelFunc variable is declared as late but is not initialized before it is used. This typically happens when the cancelFunc is referenced in a closure or callback before it is assigned a value.

I need to ensure that cancelFunc is initialized before it is used. One way to do this is to declare cancelFunc as a non-late variable and initialize it before it is used in the dismissFunc.

Explanation of Changes

  • Initialization of cancelFunc:

The cancelFunc is no longer declared as late. Instead, it is initialized with a dummy function (CancelFunc cancelFunc = () {};) to ensure it has a value before it is used in the dismissFunc.

  • Reassignment of cancelFunc:

After the dismissFunc is defined, the cancelFunc is reassigned to the result of showWidget. This ensures that cancelFunc is properly initialized before it is used.

Why This Fix Works

The issue arises because the dismissFunc references cancelFunc before it is assigned a value. By initializing cancelFunc with a dummy function and then reassigning it later, we ensure that cancelFunc is never in an uninitialized state when it is used.

@melWiss
Copy link

melWiss commented Jan 13, 2025

is the code formatted

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.

2 participants