30

I'm looking for a way to enable the autofill for a password textfield in a login form

As a backup solution, I was thinking to save the password in the secure storage, and then, with the biometrics, recovering the same password when a new login is performing.

But this won't cover all the autofill password experiences from iOS 12. For example the password won't be saved across multiple devices.

Any tips?

Andrea Miotto
  • 7,084
  • 8
  • 45
  • 70

3 Answers3

62

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]),
        ],
      ),
    );
  }
Nils Reichardt
  • 3,195
  • 2
  • 18
  • 28
  • Is using `AutofillGroup` mandatory to make this work? Or does it also work without? – LOLWTFasdasd asdad Sep 09 '20 at 09:58
  • 2
    @LOLWTFasdasdasdad It should work without `AutofillGroup`, but the UX is better if you use it. Read more about it [here](https://api.flutter.dev/flutter/widgets/AutofillGroup-class.html) – Aleksandar Feb 03 '21 at 13:03
  • I still can't don't get anything auto-filled. – bounxye Mar 23 '21 at 14:50
  • 1
    I solved with migrating to flutterEmbedding v2, big thanks to https://stackoverflow.com/a/64861651/9815944. – bounxye Mar 29 '21 at 13:18
  • In my case I use AutofillHints.username and AutofillHints.password. If I tap on the username text field, choose the stored username + password and let it be filled, it doesn't automatically fill the password text field - I have to repeat the process. What needs to be changed to automatically achieve this? – Colibri Feb 15 '22 at 12:22
  • @Colibri did you manage to make all the fields be filled in one swoop? – Andre Oliveira Feb 24 '22 at 17:08
  • This doesn't work with SDK 2.10.0, I've tried with a sample app. – Philipos D. Mar 30 '22 at 15:02
5

Auto-Fill is not yet supported in flutter out of the box. There are two issues i know of which are tracking this issue (although android related). You might want to subscribe/vote on those:

I fear it won't be easy to trigger this functionality via a 3rd party plugin though.

As for your question regarding secure storage: If you are using the flutter secure storage plugin which uses the keychain on iOS, it should be synced across devices via iCloud.

Herbert Poul
  • 4,512
  • 2
  • 31
  • 48
5

I had an autofill on both an email input and password input on the same page. The autofill was only showing on the password field.

I had to wrap the TextFields in an AutoFillGroup for them to show on both!

Micheal C Wallas
  • 495
  • 6
  • 14