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] TextInput.finishAutofillContext() doesn't bring up the system prompt #116889

Open
lukaszdebowski opened this issue Dec 12, 2022 · 20 comments
Labels
a: text input Entering text in a text field or keyboard related problems found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@lukaszdebowski
Copy link

lukaszdebowski commented Dec 12, 2022

I do have the autofill service setup in my flutter app on iOS (including associated domains).
The api doesn't seem to work as it's explained in the docs. See below:

Steps to Reproduce

  1. Fill email input field
  2. Fill password input field
  3. Press the "Next" button which calls TextInput.finishAutofillContext()

Expected results:

iOS prompt to save the password should appear

Actual results:

iOS prompt to save the password appears after the password input loses the focus (i.e pressing the done button on the keyboard).
Pressing the "Next" button does not do anything.

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(_title),
        ),
        body: const MyStatefulWidget(),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({super.key});

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  final TextEditingController email = TextEditingController();
  final TextEditingController password = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        AutofillGroup(
          onDisposeAction: AutofillContextAction.cancel,
          child: Column(
            children: <Widget>[
              TextField(
                controller: email,
                autofillHints: const <String>[AutofillHints.email],
                keyboardType: TextInputType.emailAddress,
              ),
              TextField(
                controller: password,
                autofillHints: const <String>[AutofillHints.password],
                keyboardType: TextInputType.visiblePassword,
              ),
              ElevatedButton(
                onPressed: () {
                  TextInput.finishAutofillContext(shouldSave: true);
                },
                child: const Text('Next'),
              ),
              ElevatedButton(
                onPressed: () {
                  FocusScope.of(context).unfocus();
                },
                child: const Text('Unfocus'),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
flutter doctor -v
rni-mobile % flutter doctor -v
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-US)
    • Flutter version 3.3.9 on channel stable at /Users/lukaszdebowski/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (3 weeks ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/lukaszdebowski/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.74.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.54.0

See attached video (it shows another bug, which is the fact that the prompt did not show up at the first time at all)

output.mp4

App running on iOS 16.1.2

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Dec 13, 2022
@darshankawar
Copy link
Member

Thanks for the report @lukaszdebowski
I used the code sample provided and ran it on latest stable and beta using iOS device running on 15.3.1, and was able to see the system prompt upon tapping next button as expected:

RPReplay-Final1670915062.MP4

In your video, I see that after inputing email and password each, you are tapping on done button and then on next button, but I didn't try that way, as the natural thing is to tap in next input field to make it active and then tapping on next button. This is something you can try and see if it shows the expected behavior or not.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 13, 2022
@github-actions
Copy link

github-actions bot commented Jan 3, 2023

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.

@github-actions github-actions bot closed this as completed Jan 3, 2023
@lukaszdebowski
Copy link
Author

So you did exactly the thing I described as "iOS prompt to save the password appears after the password input loses the focus".

The point of the bug is that the prompt should be shown upon calling TextInput.finishAutofillContext(), and that is not the case - the prompt is not shown when someone calls that method, and instead it is only shown after the password input loses focus

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 3, 2023
@github-actions github-actions bot reopened this Jan 3, 2023
@darshankawar
Copy link
Member

Thanks for the update.

stable, master flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.3.10 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (15 hours ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.7.0-13.0.pre.138, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.7.0-13.0.pre.138 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b938dc13df (18 hours ago), 2023-01-02 05:47:23 -0500
    • Engine revision 472e34cbbc
    • Dart version 3.0.0 (build 3.0.0-76.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



@darshankawar darshankawar added platform-ios iOS applications specifically has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. and removed in triage Presently being triaged by the triage team labels Jan 3, 2023
@darshankawar
Copy link
Member

/cc @LongCatIsLooong

@goderbauer goderbauer added the P2 Important issues not at the top of the work list label Jan 3, 2023
@KevinJ1008
Copy link

KevinJ1008 commented May 12, 2023

After some survey of this issue, I discover once we using GestureDetecter to wrap our widget or/and implementing keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag in ListView/CustomScrollView, technically we lose TextField's focus, which will cause system prompt not shown in iOS neither password suggestion. Android will work fine, except for password suggestion.

Doctor output
[✓] Flutter (Channel stable, 3.7.6, on macOS 13.2.1 22D68 darwin-arm64, locale zh-Hant-TW)
    • Flutter version 3.7.6 on channel stable at /Users/wunbinjhou/FlutterDevelopment/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12cb4eb7a0 (2 months ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/WunBinJhou/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/WunBinJhou/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

@eugeniobaglieri
Copy link

eugeniobaglieri commented May 12, 2023

Same problem here, on iOS the save prompt appears on focus lost and never when manually calling TextInput.finishAutofillContext()

Has someone found a solution?

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team labels Jul 8, 2023
@andynvt
Copy link

andynvt commented Aug 14, 2023

Same issue here. Android works fine on both emulators & real devices. But iOS real device is not working

@bakht200
Copy link

bakht200 commented Aug 21, 2023

@andynvt
I was facing the same issue for iOS but now its implemented.

Kindly use github or anydomain for apple-app-site-association file.

use this website for validating you file
https://branch.io/resources/aasa-validator/

`{
"webcredentials": {
"apps": [
"TeamId.BundleId"
]
},
"applinks": {
"apps": [
"TeamId.BundleId"

    ],
    "details": [
        {
            "appID":        "TeamId.BundleId"
            "paths": [
                "*"
            ]
        }
    ]
}

}

`
add an associated domain in the xcode as shown in the below picture.

Screenshot 2023-08-21 at 7 21 27 PM

enable autofill by clicking on the capability

@jsc57x
Copy link

jsc57x commented Oct 4, 2023

I don't know if we have the exact same problem but in our application the question for saving login credentials always shows up after the login, so this might be related to the disposal of the text fields.

Additonally we have the problem that the user credentials are saved but not reassociated to the text fields (This seems to be shown in the video but I'm not quite sure if this is the same problem) see #135948

@naveeninnocito

This comment was marked as duplicate.

@masterwok
Copy link

@jsc57x I'm facing the same two issues on iOS that you described in your ticket. The request to save password is always presented (even though the credentials are already saved) and the user is forced to tap "Passwords" to manually select their credentials (it even shows unassociated domains).

I'm using the developer alternative mode and have correctly hosted the associated domains file according to the documentation.

@hbali
Copy link

hbali commented Feb 6, 2024

is there any update about this? basically autofill is useless on ios if you are using different logic than "user will press the next/login button when finishing input without dismissing the keyboard". As soon as the keyboard is dismissed (user scrolls, taps somewhere etc), the prompt will show and we cannot control this at all. setting AutofillContextAction.cancel doesn't work either, the behavior is exactly the same.
Also if there is an async login process, you only want to save the data if it's correct, right? makes no sense to save it just after being input..

@ingmferrer
Copy link

Can confirm that AutofillContextAction.cancel is not working at all, it just brings up the save password prompt when the autofillgroup is destroyed.

@sybrands-place
Copy link

Flutter 3.19.3 focus issue still ocuring:

using code:

Form(
  key: _formKey,
  child: AutofillGroup(
    onDisposeAction: AutofillContextAction.cancel,
    child: ... (TextField with AutofillHints.email and another for AutofillHints.password)

Everytime when pressing on the background for unfocus after using the first TextField it triggers commit, but when using the second field after a unfocus event it stops doing it even if the button has "TextInput.finishAutofillContext();" action on it.

Converted.mp4

@brahimchebbi

This comment was marked as duplicate.

@anton-kaliuzhnyi-altexsoft

This comment was marked as duplicate.

@martesabt
Copy link

Hi,
In my case the prompt is never shown on iOS, neither when using:
TextInput.finishAutofillContext(shouldSave: true);

On Android works perfectly, using finishAutofillContext or not.

I have tried this in Flutter versions 3.13.8 and 3.19.5.

I have tested my server app-site-association file with app-site-association test, and it returns the file correctly.

@mesterbence
Copy link

Any updates? Can somebody fix it on iOS?

@motiapp
Copy link

motiapp commented May 8, 2024

Can confirm that AutofillContextAction.cancel is not working at all, it just brings up the save password prompt when the autofillgroup is destroyed.

Confirming this issue still exists in Flutter 3.19.6 on iOS 17.4.1 on multiple devices (physical and simulators). It also happens when the form loses focus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

No branches or pull requests