Last updated:
0 purchases
flutter autofill
flutter_autofill #
Provides Android Autofill support for Flutter text fields.
Supports all Android hint types.
Add dependency #
dependencies:
flutter_autofill: ^0.4.1
copied to clipboard
Usage #
At its simplest form, you can just wrap your TextField with Autofill widget:
import 'package:flutter_autofill/flutter_autofill.dart';
copied to clipboard
Autofill(
onAutofilled: (val) {
// set value in controller & cursor position after auto-filled value
_emailController.value = TextEditingValue(text: val, selection: TextSelection.fromPosition(TextPosition(offset: val.length)));
},
autofillHints: [FlutterAutofill.AUTOFILL_HINT_EMAIL_ADDRESS],
autofillType: FlutterAutofill.AUTOFILL_TYPE_TEXT,
textController: _emailController,
child: TextField(
controller: _emailController,
decoration: InputDecoration(hintText: "Please enter your email"),
),
),
copied to clipboard
For Autofill to function properly and be available on subsequent visits of screen, you must notify Autofill when data has been submitted or cancelled.
bool commited = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Autofill Widget screen'),
),
body: WillPopScope(
onWillPop: () async {
if (!commited) {
await FlutterAutofill.cancel();
}
return true;
},
child: ...
copied to clipboard
void _onSubmit() async {
await FlutterAutofill.commit();
commited = true;
...
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.