Sign In Form
Loading preview
Starting the Flutter app
A clean and straightforward sign-in form with essential fields and validation. Perfect for applications requiring a minimal authentication interface.
import 'package:flutter/material.dart';
class SignInPage1 extends StatefulWidget {
const SignInPage1({super.key});
@override
State<SignInPage1> createState() => _SignInPage1State();
}
class _SignInPage1State extends State<SignInPage1> {
bool _isPasswordVisible = false;
bool _rememberMe = false;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Form(
key: _formKey,
child: Center(
child: Card(
elevation: 8,
child: Container(
padding: const EdgeInsets.all(32.0),
constraints: const BoxConstraints(maxWidth: 350),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const FlutterLogo(size: 100),
_gap(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
"Welcome to Flutter!",
style: Theme.of(context).textTheme.titleMedium,
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
"Enter your email and password to continue.",
style: Theme.of(context).textTheme.bodySmall,
textAlign: TextAlign.center,
),
),
_gap(),
TextFormField(
validator: (value) {
// add email validation
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
bool emailValid = RegExp(
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$",
).hasMatch(value.trim());
if (!emailValid) {
return 'Please enter a valid email';
}
return null;
},
decoration: const InputDecoration(
labelText: 'Email',
hintText: 'Enter your email',
prefixIcon: Icon(Icons.email_outlined),
border: OutlineInputBorder(),
),
),
_gap(),
TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
if (value.length < 6) {
return 'Password must be at least 6 characters';
}
return null;
},
obscureText: !_isPasswordVisible,
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
prefixIcon: const Icon(Icons.lock_outline_rounded),
border: const OutlineInputBorder(),
suffixIcon: IconButton(
tooltip: _isPasswordVisible ? 'Hide password' : 'Show password',
icon: Icon(
_isPasswordVisible
? Icons.visibility_off
: Icons.visibility,
),
onPressed: () {
setState(() {
_isPasswordVisible = !_isPasswordVisible;
});
},
),
),
),
_gap(),
CheckboxListTile(
value: _rememberMe,
onChanged: (value) {
if (value == null) return;
setState(() {
_rememberMe = value;
});
},
title: const Text('Remember me'),
controlAffinity: ListTileControlAffinity.leading,
dense: true,
contentPadding: const EdgeInsets.all(0),
),
_gap(),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Sign in',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
/// do something
}
},
),
),
],
),
),
),
),
),
),
);
}
Widget _gap() => const SizedBox(height: 16);
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Everything sits in one elevated Card, capped at 350px by BoxConstraints, with a SingleChildScrollView inside so the form stays reachable on short screens. _SignInPage1State tracks _isPasswordVisible and _rememberMe, and validators require a matching email and at least six password characters. A valid form then lands on a /// do something comment, and with no controllers the values are never captured.
Adapting it
- Add controllers, call your auth service at that comment, and disable the
ElevatedButtonwhile it runs. - The email
RegExponly checks format, so confirm the address on your server. - Replace
FlutterLogoandWelcome to Flutter!with your branding, and persist_rememberMe.