Search code examples
flutterdartdart-null-safety

flutter passing a function with parameters


I've an issue with a function that I pass as parameter. I dont understand why I've this error 'the parameter '' can't have a 'null' because of its type'

I made a function that Push a new screen in my statefull class (changeAuthScreen). And I call it and my widget function ButtonAuth (onPressed). the class where there's the error

the function that I use for call the class

where this function is called


Solution

  • The issue raise because of null-safety aware. While the bool is final, you need to make it required like or provide default value .

    const AuthScreen({super.key, required this.newUser});
    

    or

    const AuthScreen({super.key, this.newUser = false});
    

    Find more about understanding-null-safety