2

I basically have a login page where the user can create an account, and a sign in page.

I want to save the user email and password in the Keychain like sooo many apps, but I'm still not able to get this prompt :

enter image description here

With this Flutter code : (copy/paste/run)

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

void main() {
  runApp(MyApp());
}


class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: AutoFillPage(),
    );
  }
}

class AutoFillPage extends StatefulWidget {
  const AutoFillPage({Key? key}) : super(key: key);

  @override
  _AutoFillPageState createState() => _AutoFillPageState();
}

class _AutoFillPageState extends State<AutoFillPage> {
  var isSameAddress = true;

  final billingAddress1Key = UniqueKey();
  final billingAddress2Key = UniqueKey();
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(
      title: Text(
          "Auto Fill"
      ),
    ),
    body: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Form(
        key: _formKey,
        child: AutofillGroup(
          onDisposeAction: AutofillContextAction.commit,
          child: ListView(
            padding: EdgeInsets.symmetric(horizontal: 16),
            children: [
              Column(
                children: [
                  TextFormField(
                    autofillHints: [AutofillHints.email],
                    validator: (value) =>
                    value!.isEmpty ? "some email please" : null,
                    decoration: const InputDecoration(
                      labelText: 'email',
                      hintText: 'enter email adress',
                    ),
                  ),
                  TextFormField(
                    autofillHints: [AutofillHints.password],
                    validator: (value) =>
                    value!.isEmpty ? "some password please" : null,
                    decoration: const InputDecoration(
                      labelText: 'password',
                      hintText: 'enter your password',
                    ),
                  ),
                ],
              ),
              MaterialButton(
                child: Text("submit"),
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    TextInput.finishAutofillContext(shouldSave: true);
                    debugPrint("----> Naigate to 2nd Page");
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => SecondRoute()),
                    );
                  }
                },
              ),
            ],
          ),
        ),
      ),
    ),
  );

  @override
  void dispose() {
    debugPrint("Form widget disposed");
    super.dispose();
  }
}

class SecondRoute extends StatefulWidget {
  @override
  _SecondRouteState createState() => _SecondRouteState();
}

class _SecondRouteState extends State<SecondRoute> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second Route"),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            debugPrint("----> Naigate back to first page");
            Navigator.pop(context);
            //Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => MyApp()));
          },
          child: Text('Go back!'),
        ),
      ),
    );
  }

  @override
  void dispose() {
    debugPrint("2nd Screen widget disposed");
    super.dispose();
  }
}

I have enabled on my real device iPhone 12 Pro Max password saving and auto fill.

I also would like to make it work on the other side with the sign in page : when the first fill is tapped I want to get the auto fill prompt (like Netflix, amazon...) to sign in quickly.

The basic code here is working on Android but not on iOS. Is there additional config needed for iOS that I could miss ?

Thanks for any help/lead

nicover
  • 2,213
  • 10
  • 24

1 Answers1

2

You need to setup associated domains for iOS: https://developer.apple.com/documentation/xcode/supporting-associated-domains

Doc:

https://api.flutter.dev/flutter/material/TextField/autofillHints.html

Setting up iOS autofill: To provide the best user experience and ensure your app fully supports password autofill on iOS, follow these steps:

  • Set up your iOS app's associated domains.
  • Some autofill hints only work with specific keyboardTypes. For example, AutofillHints.name requires TextInputType.name and AutofillHints.email works only with TextInputType.emailAddress. Make sure the input field has a compatible keyboardType. Empirically, TextInputType.name works well with many autofill hints that are predefined on iOS.

I called TextInput.finishAutofillContext but the autofill save prompt isn't showing

iOS: iOS may not show a prompt or any other visual indication when it saves user password. Go to Settings -> Password and check if your new password is saved. Neither saving password nor auto-generating strong password works without properly setting up associated domains in your app. To set up associated domains, follow the instructions in developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app. For the best results, hint strings need to be understood by the platform's autofill service. The common values of hint strings can be found in AutofillHints, as well as their availability on different platforms.

ANDYNVT
  • 531
  • 4
  • 19