Home > OS >  I'm getting errors for my controller listener in Flutter
I'm getting errors for my controller listener in Flutter

Time:07-26

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();
    }
  }

CodePudding user response:

Pay attention that when you are calling:

await _passwordsService.updatePassword(
      documentId: password.documentId,
      url: url,
    );

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.

void _userPasswordControllerListener() async {
    final password = _password;
    if (password == null) {
      return;
    }
    final userpassword = _userPasswordController.text;
    await _passwordsService.updatePassword(      //// <----
      documentId: password.documentId,
      userpassword: userpassword,
    );
  }

The method updatePassword has five required arguments:

updatePassword({
    required String documentId,   /// <-------
    required String title,        /// <-------
    required String email,        /// <-------
    required String userpassword, /// <-------
    required String url,          /// <-------
   })

so you must pass all of them.

An example call could be:

await _passwordsService.updatePassword(     
          documentId: password.documentId,
          userpassword: userpassword,
          title: YOUR_TITLE,
          url: YOUR_URL,
          email: YOUR_EMAIL
        );

CodePudding user response:

In updatePassword method you specified title, email, userpassword and url as required.

You can make them optional:

Future<void> updatePassword({
    required String documentId,
    String? title,
    String? email,
    String? userpassword,
    String? url,
  }) async {
    try {
      if (title != null) await passwords.doc(documentId).update({titleFieldName: title});
      if (email != null) await passwords.doc(documentId).update({emailFieldName: email});
      if (userpassword != null) await passwords.doc(documentId).update({userpasswordFieldName: userpassword});
      if (url != null) await passwords.doc(documentId).update({urlFieldName: url});
    } catch (e) {
      throw CouldNotUpdatePasswordException();
    }
  }
  • Related