My flutter code is built against web and android. I'm trying to make autofill for LastPass password manager to populate my login and password fields. Although the code works on the web, it doesn't work on Android.
I've been struggling with this for quite a while and still not sure what's the issue. I'm building against Android target 34 (min 33) versions. The code is below is mostly my code (up to paddings and other contains in the list). I also have android:autofillHints
set in the (main) AndroidManifest.xml (code belower).
To be clear, I'm not an android nor web developer. I've been working with Flutter close to two years and I have a production app but I'm still confused by a lot of flutter/android things. Help?
Relevant(?) part of the Widget build()
function:
return Form(
key: _formKey,
child: SigningLayout(
child: AutofillGroup(
child: Column(
children: <Widget>[
Container(
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
controller: emailController,
validator: validateEmail,
autofillHints: [AutofillHints.email],
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email',
),
),
),
Container(
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
obscureText: _isPassObscure,
controller: passwordController,
validator: validatePassword,
autofillHints: [AutofillHints.password],
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
suffixIcon: IconButton(
icon: Icon(_isPassObscure ? Icons.visibility : Icons.visibility_off),
onPressed: togglePassVis,
tooltip: 'Toggle password visibility',
),
),
),
),
],
),
),
),
);
Some content from android/app/src/main/AndroidManifest.xml
{{ snip }}
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:autofillHints="emailAddress, password"
android:windowSoftInputMode="adjustResize">
{{ snip }}
My flutter code is built against web and android. I'm trying to make autofill for LastPass password manager to populate my login and password fields. Although the code works on the web, it doesn't work on Android.
I've been struggling with this for quite a while and still not sure what's the issue. I'm building against Android target 34 (min 33) versions. The code is below is mostly my code (up to paddings and other contains in the list). I also have android:autofillHints
set in the (main) AndroidManifest.xml (code belower).
To be clear, I'm not an android nor web developer. I've been working with Flutter close to two years and I have a production app but I'm still confused by a lot of flutter/android things. Help?
Relevant(?) part of the Widget build()
function:
return Form(
key: _formKey,
child: SigningLayout(
child: AutofillGroup(
child: Column(
children: <Widget>[
Container(
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
controller: emailController,
validator: validateEmail,
autofillHints: [AutofillHints.email],
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email',
),
),
),
Container(
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
obscureText: _isPassObscure,
controller: passwordController,
validator: validatePassword,
autofillHints: [AutofillHints.password],
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
suffixIcon: IconButton(
icon: Icon(_isPassObscure ? Icons.visibility : Icons.visibility_off),
onPressed: togglePassVis,
tooltip: 'Toggle password visibility',
),
),
),
),
],
),
),
),
);
Some content from android/app/src/main/AndroidManifest.xml
{{ snip }}
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:autofillHints="emailAddress, password"
android:windowSoftInputMode="adjustResize">
{{ snip }}
Share
Improve this question
edited Jan 28 at 14:32
Dawid Laszuk
asked Jan 25 at 3:25
Dawid LaszukDawid Laszuk
1,97828 silver badges44 bronze badges
3 Answers
Reset to default 1I fear this won't help much, but I scribbled up a MRE and ran it on my physical device, and the autofill works just fine. The device's Android version is 34, flutter is updated at 3.27.1. Maybe there's something else messing with the Textfield behavior? You can try starting almost from scratch and see if with a fresh start the issue persists...
Here's the full code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final emailController = TextEditingController();
final passwordController = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Form(
key: _formKey,
child: AutofillGroup(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.all(12),
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
controller: emailController,
validator: validateEmail,
autofillHints: [AutofillHints.email],
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email',
),
),
),
Container(
padding: EdgeInsets.all(12),
child: TextFormField(
onFieldSubmitted: ((value) => formSubmit()),
controller: passwordController,
validator: validateEmail,
autofillHints: [AutofillHints.password],
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
),
],
),
),
),
),
),
);
}
bool formSubmit() {
if (_formKey.currentState?.validate() ?? false) {
return true;
}
return false;
}
String validateEmail(String? value) => "no";
}
Verbose flutter doctor results:
[√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Versione 10.0.26100.2894], locale it-IT)
• Flutter version 3.27.1 on channel stable at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 17025dd882 (6 weeks ago), 2024-12-17 03:23:09 +0900
• Engine revision cb4b5fff73
• Dart version 3.6.0
• DevTools version 2.40.2
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at C:\Users\****\AppData\Local\Android\sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 21.0.4+-12508038-b607.1)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.4)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.12.35707.178
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2024.2)
• Android Studio at C:\Program Files\Android\Android Studio
• 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 21.0.4+-12508038-b607.1)
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Versione 10.0.26100.2894]
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.267
• Edge (web) • edge • web-javascript • Microsoft Edge 131.0.2903.112
[√] Network resources
• All expected network resources are available.
I'd suggest checking a few things:
- make sure you are not using multiple AutofillGroup widgets nested within each other.
- try testing it on a separate screen with only an AutofillGroup and a couple of TextField widgets instead TextFormField.
AutofillGroup(
child: Column(
children: [
TextField(
autofillHints: const [AutofillHints.email],
decoration: InputDecoration(labelText: 'Email'),
),
TextField(
autofillHints: const [AutofillHints.password],
obscureText: true,
decoration: InputDecoration(labelText: 'Password'),
),
],
),
)
In my projects autocomplete works using TextField widget. It would be great if you could send a link to the repository to check it out
My flutter doctor output with minSdkVersion 21, targetSdk 34:
[✓] Flutter (Channel stable, 3.16.9, on macOS 13.6.7 22G720 darwin-arm64, locale en-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Community Edition (version 2022.2.3)
[✓] VS Code (version 1.96.4)
[✓] Connected device (3 available)
...
Have you enabled autofill on your device in the phone settings?
Based on the autofill docs:
Android autofill: Go to Settings -> System -> Languages & input -> Autofill service. Enable the autofill service of your choice, and make sure there are available credentials associated with your app.