Skip to main content
February 24, 2022
Question

Autofill password field not triggering on (Android devices) for Flutter

  • February 24, 2022
  • 41 replies
  • 6278 views

Password field in Flutter, working fine with Iphones but for Android the password field is never autofilling.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

41 replies

December 30, 2022

Sure, @rekire. Here you go: https://github.com/periah/autofill-flutter

December 31, 2022

@peri Great effort and interesting solution!

Unfortunately it doesn't solve the issue in the grand scheme of things as Flutter's native platform views come with a lot of caveats and tradeoffs and are still experimental on several platforms. Not to mention that you would have to write your own implementations of all widgets that use TextField under the hood (eg. TextFormField).

So, while I applaud this, I just wanted to make it clear to the 1Password folks that this is sadly not a suitable workaround for most developers.

January 6, 2023

The inputType for Flutter fields always returns 0, it seems. I've run an autofill sample from this codebase (after migrating it to the latest Room which causes compile errors), https://github.com/android/input-samples/tree/main/AutofillFramework and this code can detect password fields and offer to fill them based on the 'hint' field alone. Would it be possible to have a user setting in 1Password that relaxes the inputType = password stipulation and allows autofill on fields with a hint of 'password'? Just curious if that'd be acceptable or not?

This is what the code sees when a password field is focused in a Flutter app I'm working on. In the sample code it iterates through the view nodes that flutter is producing, and it is able to properly get the autofill hints, however asking what the inputType of the node is always returns 0. The AutoFillType is TEXT which seems fine. Here's a little output from the run:

D/BasicService: inputType = 0
D/BasicService: autofillType = 1
D/BasicService: autoFillHints = [password]
V/BasicService: Setting hint 'password' on 1073741824:543304862@2145823823
D/BasicService: autofillable fields:{password=1073741824:543304862@2145823823}

So, I guess my question stands, can 1Password just use the autoFillType and autoFillHints to allow flutter apps to be autofilled, like Google's sample app does?

January 6, 2023

@tjarvstrand Thanks for the kudos!

This is by no means a be-all and end-all solution. It was just what I came up with as a possibility while we see if there's other ways around this. Using the demo app @ricardoboss made as an example, there is only one Autofill group with two fillable fields, which is something that can be done with my suggestion. There's also a plugin I found which does the same thing I suggested (only better since i'm not a Flutter developer 😁).

I hear you and I'm looking into ways to improve filling in Flutter apps on our end. I hope to have something to report soon!

ricardoboss
January 6, 2023

@peri Thank you for working on this!

I looked at the repository of yours but I'm having trouble finding the relevant parts of code. Is there a way to add your solution to an existing Flutter app? Can you highlight any code related to the problem?

Thanks!

January 7, 2023

Hey @ricardoboss!. I've basically just adapted what's in this Flutter guide:

https://docs.flutter.dev/development/platform-integration/android/platform-views

The difference is that I created the text fields in the Kotlin code rather than Dart. The relevant part is that I created a NativeView.kt class where I initialize the text field:

```
internal class NativeView(context: Context, id: Int, creationParams: Map?) :
PlatformView {
private val textView: EditText

override fun getView(): View {
    return textView
}

override fun dispose() {}

init {
    textView = android.widget.EditText(context)
    textView.setHint("username")
    textView.setAutofillHints(android.view.View.AUTOFILL_HINT_EMAIL_ADDRESS)
    textView.setBackgroundColor(Color.rgb(230, 230, 250))
    textView.setGravity(android.view.Gravity.CENTER)

}

```
Then I refer to the view in the Dart code, rather than using the TextField widget.

That said, hopefully we can get something better than this workaround out as a solution. I'll keep you all posted here!

January 17, 2023

@peri thank you for working on this.

I am also having trouble with 1Password autofill for our Flutter app on Android.
I spent a lot of time debugging this issue but could not find a workaround.

I created an Android app with a TextField which had the inputType="textPassword", and 1Password did trigger in that case.
This confirms the suspicion that the problem has something to do with Flutter incorrectly reporting the inputType to the AutoFill service.

However other Password managers who also work with the Autofill framework - like Bitwarden - seem to be working fine without this additional requirement for inputType. Maybe 1Password could look into doing something similar to the Bitwarden Android app.

Thanks!

January 27, 2023

Indeed @ytomassen. The Flutter TextField doesn't have an inputType, which is why it's not working there. I'm currently looking into ways to improve the experience for Flutter developers without needed development on the Flutter end, and I'll keep you posted when I have something to report!

February 3, 2023

@ytomassen @tjarvstrand @nealsanche @ricardoboss @rekire @mtambucho @AugustoResende

I made a change in our latest https://releases.1password.com/android/beta/#1password-for-android-8.10.0-9 that should allow filling in Flutter apps. Give it a try!

February 3, 2023

I have given it a try and it works! Thanks very much.