Skip to content

Instantly share code, notes, and snippets.

@lesnitsky
Created February 2, 2022 15:27
Show Gist options
  • Save lesnitsky/690a61e5fd7043f9e48e5d076ab24e15 to your computer and use it in GitHub Desktop.
Save lesnitsky/690a61e5fd7043f9e48e5d076ab24e15 to your computer and use it in GitHub Desktop.
Email form
class EmailForm extends StatelessWidget {
final VoidCallback onSubmitted;
final TextEditingController emailCtrl;
final TextEditingController passwordCtrl;
const EmailForm({
Key? key,
required this.onSubmitted,
required this.emailCtrl,
required this.passwordCtrl,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: AutofillGroup(
child: Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
TextField(
autofocus: true,
keyboardType: TextInputType.emailAddress,
autofillHints: const [
AutofillHints.email,
AutofillHints.username,
AutofillHints.newUsername,
],
controller: emailCtrl,
decoration: const InputDecoration(
labelText: 'Email',
),
),
const SizedBox(height: 16),
TextField(
obscureText: true,
autofillHints: const [AutofillHints.password],
controller: passwordCtrl,
onSubmitted: (v) {
onSubmitted();
},
decoration: const InputDecoration(
labelText: 'Password',
),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: onSubmitted,
child: const Text('Sign in'),
),
],
),
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment