I am building a password manager flutter application and I’m using Firestore database to store the data(passwords) entered by the users. I have created 4 different text fields on my Flutter application and on the firestore database, namely : title, email, userpassword and url.
I am getting some errors for my listeners.
void _titleControllerListener() async {
final password = _password;
if (password == null) {
return;
}
final title = _titleController.text;
await _passwordsService.updatePassword(
documentId: password.documentId,
title: title,
);
}
void _emailControllerListener() async {
final password = _password;
if (password == null) {
return;
}
final email = _emailController.text;
await _passwordsService.updatePassword(
documentId: password.documentId,
email: email,
);
}
void _userPasswordControllerListener() async {
final password = _password;
if (password == null) {
return;
}
final userpassword = _userPasswordController.text;
await _passwordsService.updatePassword(
documentId: password.documentId,
userpassword: userpassword,
);
}
void _urlControllerListener() async {
final password = _password;
if (password == null) {
return;
}
final url = _urlController.text;
await _passwordsService.updatePassword(
documentId: password.documentId,
url: url,
);
}
Errors: These 4 four errors are repeated for a total of 24 errors.
The named parameter 'url' is required, but there's no corresponding argument.
Try adding the required argument.
The named parameter 'email' is required, but there's no corresponding argument.
Try adding the required argument.
The named parameter 'userpassword' is required, but there's no corresponding argument.
Try adding the required argument.
The named parameter 'title' is required, but there's no corresponding argument.
Try adding the required argument.
update password() code(I’m not getting any errors here).
Future<void> updatePassword({
required String documentId,
required String title,
required String email,
required String userpassword,
required String url,
}) async {
try {
await passwords.doc(documentId).update({titleFieldName: title});
await passwords.doc(documentId).update({emailFieldName: email});
await passwords.doc(documentId).update({userpasswordFieldName: userpassword});
await passwords.doc(documentId).update({urlFieldName: url});
} catch (e) {
throw CouldNotUpdatePasswordException();
}
}
3
Answers
I was able to solve the errors by splitting the updatePassword() code into 4 different functions. 1 function for each text field.
After creating the above 4 updatePassword functions. I made changes to the controller listeners. So, that they call their own updatePassword function.
Pay attention that when you are calling:
You are not passing all required parameters. You have various calls to this method and each time you are calling it with different arguments.
I.E.
The method updatePassword has five required arguments:
so you must pass all of them.
An example call could be:
In
updatePassword
method you specifiedtitle
,email
,userpassword
andurl
as required.You can make them optional: