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,),
These kind of issue comes when you declare the constructor like:
In this case the following is the correct initialisation code (you can't use named parameter):
If you really need to use named parameter, then you have to write:
and use it like:
You can read more about these concepts here: Dart language tour