Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofill Part 1 #52126

Merged
Merged

Conversation

LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Mar 6, 2020

Description

iOS PR: flutter/engine#17493
Android PR: flutter/engine#17465
Design Doc: https://flutter.dev/go/input-field-autofill

Scope

This PR (as well as the engine PRs) adds the most basic autofill functionality. It does not include some platform-specific configurations (e.g., passwordRules on iOS).

Example Usage:

  @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(ontroller: repeatNewPassword, autofillHints: [AutofillHints.newPassword]),
          if (!isNewUser) TextField(controller: password, autofillHints: [AutofillHints.password]),
        ],
      ),
    );
  }

Related Issues

Part of #13015

Tests

I added the following tests:

Replace this with a list of the tests that you added as part of this PR. A change in behaviour with no test covering it
will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See Test Coverage.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/input-field-autofill
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added framework flutter/packages/flutter repository. See also f: labels. work in progress; do not review labels Mar 6, 2020
@goderbauer
Copy link
Member

Why does the Autofill widget need to take a builder instead of just a list of controllers?

@LongCatIsLooong
Copy link
Contributor Author

@goderbauer the controllers in the list may change as the state of the form changes. In most cases it should simply follow the logic in the build method.

@goderbauer
Copy link
Member

If the controllers change, wouldn't you have to call setState anyways to assign those new controllers to the textfields? When you do that, the Autofill would also rebuild with the new list of controllers.

@LongCatIsLooong
Copy link
Contributor Author

Then in that case the list of controllers will be updated in the next build phase? If the state has already changed and the scope queries the list of controllers before the next build phase, the list we return should reflect the new state I think?

hintText: 'What do people call you?',
labelText: 'Name *',
// Since the fields are in a Column, it's easier to
// uses the non-lazy version.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case since we're using a Column, we can just wrap the entire Column inside an Autofill and omit clientListBuilder

@fluttergithubbot fluttergithubbot added d: examples Sample code and demos f: material design flutter/packages/flutter/material repository. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. labels Mar 11, 2020
@LongCatIsLooong LongCatIsLooong force-pushed the autofill-controller-list branch 5 times, most recently from 6bcb4f7 to 2cf28ff Compare March 13, 2020 08:23
@LongCatIsLooong LongCatIsLooong changed the title [WIP please do not review] Autofill with Controller list [WIP] Autofill with Controller list Mar 18, 2020
@LongCatIsLooong LongCatIsLooong changed the title [WIP] Autofill with Controller list Autofill with Controller list Mar 24, 2020
@fluttergithubbot fluttergithubbot added the f: cupertino flutter/packages/flutter/cupertino repository label Mar 24, 2020
@LongCatIsLooong LongCatIsLooong changed the title Autofill with Controller list Autofill Part 1 Mar 24, 2020
@LongCatIsLooong LongCatIsLooong force-pushed the autofill-controller-list branch 2 times, most recently from cac5fa1 to 8b11268 Compare April 3, 2020 16:52
///
/// {@template flutter.widgets.autofill.AutofillGroupState}
/// An [AutofillGroupState] can be used to register an [AutofillClient] when it
/// enteres this [AutofillGroup] (for example, when an [EditableText] is mounted or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"enteres" => "enters"

@@ -0,0 +1,166 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file's name is missing an underscore, should be: autofill_group_test.dart

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new registration-based approach.

if (method == 'TextInputClient.updateEditingStateWithTag') {
final TextInputClient client = _currentConnection._client;
assert(client != null);
if (client is AutofillTrigger) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all TextInputClient just have a currentAutofillScope getter and return null by default if they don't participate in AutoFill? (Not sure what the AutofillTrigger abstraction is adding)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality-wise I think it's the same. Adding AutofillTrigger makes it non-breaking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just landed a very similar breaking change a few days ago. I think that makes breaking this less bad?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer the cleaner API here without the type check. Implementing your own TextInputClient should be fairly un-common, so migration should be fairly easy?


/// Adds the [AutofillClient] to this [AutofillGroup].
///
/// Typically, this is be called by [AutofillTrigger]s (for example,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the "be"?

@LongCatIsLooong LongCatIsLooong force-pushed the autofill-controller-list branch 2 times, most recently from 370190d to e88c584 Compare April 14, 2020 18:32
@BirjuVachhani
Copy link

Can anyone tell me which version has these changes or is this hasn't been released yet?

@hpoul
Copy link
Contributor

hpoul commented May 4, 2020

@BirjuVachhani simply check the merge commit e31f708 which will show you all tags it is in, right now: "1.18.0-8.0.pre 1.18.0-7.0.pre 1.18.0-6.0.pre" - ie. already in the dev channel.

@BirjuVachhani
Copy link

@hpoul Thank you for the info. I did check it out and I got those changes. However I was wondering about the same in a TextFormField. Any info on that would be helpful. Thanks.

@LongCatIsLooong
Copy link
Contributor Author

LongCatIsLooong commented May 6, 2020

@hpoul @BirjuVachhani one of the commits was reverted as part of the engine roll revert, it's probably not working on android. I'll post updates in the related issue thread and hopefully close that issue soon.

@BirjuVachhani
Copy link

@LongCatIsLooong got it. Thank you for the info. 😊

@pokonski
Copy link

pokonski commented May 6, 2020

Which one is the related issue? 🤔

@akshaybengani
Copy link

Thank you very much, I was totally freaked out for such a solution, it is working properly just upgrade the flutter to master and that's it, even one-time password is also working.

Thank you once again you saved my ass.

@nausharipov
Copy link

How to invoke a prompt for saving the new username and password? I've wrapped textfields into autofillgroup, now the passwords are shown but the current is not saved

@nturgut
Copy link
Contributor

nturgut commented Jun 11, 2020

@nausharipov Thanks for asking! We are still working on that part. The tracking issue: #55613

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer: peppermint f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet