17

I have created a login form in flutter web, when I login, chrome detects the password that was entered, but offers only to save the password, while the username stays blank.

Google suggests the following HTML form so that credential manager can detect the credentials that needs to be stored.

<form id="signup" method="post">
 <input name="email" type="text" autocomplete="username email">
 <input name="display-name" type="text" autocomplete="name">
 <input name="password" type="password" autocomplete="new-password">
 <input type="submit" value="Sign Up!">
</form>

In my form I used both email and username but chrome credential manager is still not able to detect the username.

How can we create the form with autocomplete tag in flutter web?

Qiong Wu
  • 1,504
  • 1
  • 15
  • 27
max
  • 1,505
  • 3
  • 15
  • 38
  • 2
    There is an issue open in github for this. So it might take some time to get a fix for this. Follow this [issue](https://github.com/flutter/flutter/issues/13015) – Abhilash Chandran Mar 07 '20 at 12:15
  • Hope they will add web support as well – max Mar 07 '20 at 14:21
  • There is a platform-web tag attached to the issue meaning it will be handled. Check out the last comment in that issue... :) – Abhilash Chandran Mar 07 '20 at 16:36
  • 1
    strangely enough, with the latest flutter master channel framework, the autocomplete field is set correctly, but is still not recognized by chrome, anyone else tried this? – Qiong Wu May 21 '20 at 14:51

1 Answers1

24

Flutter supports now autofill (password, email, username, etc.) ☑️ The merged pull request with an example: https://github.com/flutter/flutter/pull/52126

Example:

 @override
  Widget build(BuildContext context) {
    return AutofillGroup(
      child: Column(
        children: <Widget>[
          TextField(controller: username, autofillHints: [AutofillHints.username]),
          Checkbox(
            value: isNewUser,
            onChanged: (bool newValue) {
              setState(() { isNewUser = newValue; });
            },
          ),
          if (isNewUser) TextField(controller: newPassword, autofillHints: [AutofillHints.newPassword]),
          if (isNewUser) TextField(controller: repeatNewPassword, autofillHints: [AutofillHints.newPassword]),
          if (!isNewUser) TextField(controller: password, autofillHints: [AutofillHints.password]),
        ],
      ),
    );
  }

You may need to switch to dev or master channel (flutter channel master).

Lamanus
  • 12,898
  • 4
  • 21
  • 47
Nils Reichardt
  • 3,195
  • 2
  • 18
  • 28
  • 1
    Is it implemented for web? The example here: https://api.flutter.dev/flutter/widgets/AutofillGroup-class.html ... doesn't seem to autofill anything (for desktop Chrome) – user48956 Nov 24 '20 at 00:53
  • 1
    It should work for Flutter Web, but for me personally it is very buggy. I created an issue on GitHub: https://github.com/flutter/flutter/issues/61301. Maybe you can upvote it and comment your problem. – Nils Reichardt Nov 27 '20 at 21:40
  • What if the controller is a parameter you pass to an external widget (i.e. TextFormField is an external widget that receives the controller)? I am trying autofillHints: [AutofillHints[controller]] where controller is a variable but it doesn't accept it – user3808307 Jan 07 '21 at 18:45
  • @user3808307 I think that you should create a custom implementation, like: `class MyCustomController { final TextEditingController controller; final Iterable? autofillHints; const MyCustomController( this.controller, this.autofillHints, ); }` – Adnan Jul 08 '21 at 09:38
  • 6
    To date the autoFillHints param doesn't work for Flutter Web (2.2.3) – Brandon Pillay Aug 11 '21 at 12:14
  • autofillHints: const [AutofillHints.email], which keyword i should use in this line. i am getting error. The getter 'email' isn't defined for the type 'AutofillHints'. Try importing the library that defines 'email', correcting the name to the name of an existing getter, or defining a getter or field named 'email'. – Hari .S Jan 15 '23 at 09:59