Autofill save (TextInput.finishAutofillContext) not working | FLUTTER

58 Views Asked by At

I can confirm that it is working on a real Android device, but not a real iOS device.

I am trying to implement an auto-save username and password in login. I tried the below code.

design code

AutofillGroup(
                  child: Form(
                    key: _formKey1,
                    child: ListView(
                      children: [
                        CusFormField(
                          autofillEmail: true,
                          hintText: 'Enter your email address',
                          text: 'Email Address',
                          controller: _emailController,
                          keyboardType: TextInputType.emailAddress,
                          validator: (value) {
                            return emailValidator(value);
                          },
                        ),
                        CusFormField(
                          autofillPassword: true,
                          obscureText: true,
                          hintText: 'Enter your password',
                          text: 'Password',
                          controller: _passwordController,
                          keyboardType: TextInputType.name,
                          validator: (value) {
                            return passwordValidator(value);
                          },
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 3.w, right: 3.w),
                          child: Container(
                            height: 50,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(5),
                                gradient: const LinearGradient(
                                    colors: [kP50, kP100])),
                            child: ElevatedButton(
                              style: ElevatedButton.styleFrom(
                                  backgroundColor: Colors.transparent,
                                  shadowColor: Colors.transparent),
                              onPressed: () {
                                if (state is! LoginLoading) {
                                  loginButtonTap();
                                }
                              },
                              child:Text('Login', style: smMedium(kWhite300)),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                );

custom form field code

// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:facegen/core/config/colors.dart';
import 'package:facegen/core/config/text_styles.dart';
import 'package:responsive_sizer/responsive_sizer.dart';

class CusFormField extends StatelessWidget {
  final bool obscureText;
  final bool autofillEmail;
  final bool autofillPassword;
  final TextEditingController controller;
  final String text;
  final String hintText;
  final TextInputType keyboardType;
  final List<TextInputFormatter>? inputFormatters;
  final String? Function(String?)? validator;
  final bool isEnabled;

  const CusFormField({
    super.key,
    this.obscureText = false,
    this.autofillEmail = false,
    this.autofillPassword = false,
    required this.controller,
    required this.text,
    required this.hintText,
    this.keyboardType = TextInputType.text,
    this.inputFormatters,
    this.validator,
    this.isEnabled = true,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding:
          EdgeInsets.only(left: 3.w, right: 3.w, top: 0.5.w, bottom: 0.5.w),
      child: Container(
        height: 63,
        padding:
            EdgeInsets.only(top: 0.5.w, bottom: 0.w, left: 1.5.w, right: 1.5.w),
        decoration: ShapeDecoration(
          color: kWhite,
          shape: RoundedRectangleBorder(
            side: const BorderSide(width: 0.9, color: kBlack600),
            borderRadius: BorderRadius.circular(6.68),
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              text,
              style: xs_1Regular(
                kBlack250,
              ),
            ),
            CupertinoTextFormFieldRow(
              padding: const EdgeInsets.all(0),
              controller: controller,
              obscureText: obscureText,
              keyboardType: keyboardType,
              // inputFormatters: [valid.isValidemail],
              autovalidateMode: AutovalidateMode.disabled,
              validator: validator,
              enabled: isEnabled,
              autofillHints: autofillEmail == true
                  ? [AutofillHints.username]
                  : autofillPassword == true
                      ? [AutofillHints.password]
                      : null,
              style: xsRegular(kBlack),

              placeholder: hintText,
              decoration: BoxDecoration(
                  color: kWhite,
                  border: Border.all(
                    color: Colors.transparent,
                  ),
                  borderRadius: BorderRadius.circular(8)),
            ),
          ],
        ),
      ),
    );
  }
}

I Xcode Associated Domains screen shoot

I have seen others' answers on the internet, but did not find a concrete answer. I want this question to have complete answers step by step, It can help others also. thanks

0

There are 0 best solutions below