skip to Main Content

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


  1. Chosen as BEST ANSWER

    I was able to solve the errors by splitting the updatePassword() code into 4 different functions. 1 function for each text field.

    Future<void> updatePasswordTitle({
        required String documentId,
        required String title,
      }) async {
        try {
          await passwords.doc(documentId).update({titleFieldName: title});
        } catch (e) {
          throw CouldNotUpdatePasswordException();
        }
      }
    
      Future<void> updatePasswordEmail({
        required String documentId,
        required String email,
      }) async {
        try {
          await passwords.doc(documentId).update({emailFieldName: email});
        } catch (e) {
          throw CouldNotUpdatePasswordException();
        }
      }
    
      Future<void> updatePasswordUserpassword({
        required String documentId,
        required String userpassword,
      }) async {
        try {
          await passwords.doc(documentId).update({userpasswordFieldName: userpassword});
        } catch (e) {
          throw CouldNotUpdatePasswordException();
        }
      }
    
      Future<void> updatePasswordUrl({
        required String documentId,
        required String url,
      }) async {
        try {
          await passwords.doc(documentId).update({urlFieldName: url});
        } catch (e) {
          throw CouldNotUpdatePasswordException();
        }
      }
    

    After creating the above 4 updatePassword functions. I made changes to the controller listeners. So, that they call their own updatePassword function.

    void _titleControllerListener() async {
        final password = _password;
        if (password == null) {
          return;
        }
        final title = _titleController.text;
        await _passwordsService.updatePasswordTitle(
          documentId: password.documentId,
          title: title,
        );
      }
    
      void _emailControllerListener() async {
        final password = _password;
        if (password == null) {
          return;
        }
        final email = _emailController.text;
        await _passwordsService.updatePasswordEmail(
          documentId: password.documentId,
          email: email,
        );
      }
    
      void _userPasswordControllerListener() async {
        final password = _password;
        if (password == null) {
          return;
        }
        final userpassword = _userPasswordController.text;
        await _passwordsService.updatePasswordUserpassword(
          documentId: password.documentId,
          userpassword: userpassword,
        );
      }
    
      void _urlControllerListener() async {
        final password = _password;
        if (password == null) {
          return;
        }
        final url = _urlController.text;
        await _passwordsService.updatePasswordUrl(
          documentId: password.documentId,
          url: url,
        );
      }
    

  2. 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
            );
    
    Login or Signup to reply.
  3. 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();
        }
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search