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

Stored passwords not visible on iOS' passwords page. #43

Open
juanfactor88 opened this issue Jan 23, 2024 · 0 comments
Open

Stored passwords not visible on iOS' passwords page. #43

juanfactor88 opened this issue Jan 23, 2024 · 0 comments

Comments

@juanfactor88
Copy link

juanfactor88 commented Jan 23, 2024

Hi, I'm trying to save login information from my app to iOS keychain, this is what I implemented:

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: LoginPage(),
    );
  }
}

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final _storage = FlutterSecureStorage();
  final _userController = TextEditingController();
  final _passwordController = TextEditingController();

  Future<void> _saveCredentials() async {
    await FlutterKeychain.put(key: 'username', value: _userController.text);
    await FlutterKeychain.put(key: 'password', value: _passwordController.text);
    
  }

  Future<void> _loadCredentials() async {
    String? username = await FlutterKeychain.get(key: 'username');
    String? password = await FlutterKeychain.get(key: 'password');
    setState(() {
      _userController.text = username ?? '';
      _passwordController.text = password ?? '';
    });
  }

    void _clearCredentials() async {
   // await _storage.delete(key: 'username');
    //await _storage.delete(key: 'password');
    await FlutterKeychain.remove(key: 'username');
    await FlutterKeychain.remove(key: 'password');
    await FlutterKeychain.clear();
  }

  @override
  void initState() {
    super.initState();
    //_loadCredentials();
  }

  @override
  void dispose() {
    _userController.dispose();
    _passwordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Login Page')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: AutofillGroup(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextField(
                keyboardType: TextInputType.name,
                autofillHints: [AutofillHints.username],
                controller: _userController,
                decoration: InputDecoration(labelText: 'Username'),
              ),
              TextField(
                keyboardType: TextInputType.visiblePassword,
                autofillHints: [AutofillHints.password],
                controller: _passwordController,
                decoration: InputDecoration(labelText: 'Password'),
                obscureText: true,
              ),
              ElevatedButton(
                onPressed: _saveCredentials,
                child: Text('Save Credentials'),
              ),
              ElevatedButton(
                onPressed: _loadCredentials,
                child: Text('Load Credentials'),
              ),
              ElevatedButton(
                onPressed: _clearCredentials,
                child: Text('Clear Credentials'),
              ),
            ],
          ),
        ),
      ),
    );
  }

}

This works fine on Android as I get the OS prompt to save and retrieve the password, but on iOS there is no prompt and when I search for the saved credentials in settings -> passwords, they're not there, so I can't manage those credentials from the device, nor have them on the iCloud backup.

Do I need to configure something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant