The Named Parameter isn't defined FirebaseUser

476 views Asked by At

I am just getting started with app development and flutter and I am running into this issue without any luck. I get an error that 'user' is not defined despite it being defined right above. I cannot tell what mistake I am making. Any ideas how I can tackle this problem?

final FirebaseAuth _auth = FirebaseAuth.instance;

  Future<void> registerUser() async {
      FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    )).user;

    Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => Chat(
              user: user,
            ),
        ),
    );
  }

//Error message

Compiler message:
lib/main.dart:127:40: Error: No named parameter with the name 'user'.
            builder: (context) => Chat(user: user,),
1

There are 1 answers

0
Midhun MP On BEST ANSWER

These kind of issue comes when you declare the constructor like:

Chat(this.user) {
  // Optional code
}

In this case the following is the correct initialisation code (you can't use named parameter):

Chat(user)

If you really need to use named parameter, then you have to write:

Chat({this.user}) {
  // Optional code
}

and use it like:

Chat(user: user,),

You can read more about these concepts here: Dart language tour