onlineskilllab.com onlineskilllab.com
  • Home
  • Freelancing
    Previous Next
  • Web Development/WordPress
    Previous Next
  • Tech Blogs
  • Flutter Development
  • About
  • Facebook
  • X (Twitter)
  • Instagram
Flutter Development

MAD LAB 02: Login/SignUp Page in Flutter – Complete Authentication UI with Validation & Navigation

By digitaldech March 4, 2026 4 Mins Read
Share
Facebook Twitter Pinterest LinkedIn Email

Introduction

User authentication is a core requirement of almost every mobile application. Whether you are building an e-commerce app, LMS, social media platform, or university portal system, you must implement a secure and user-friendly Login and SignUp interface.

In this complete guide, you will learn:

  • How to create Login and SignUp UI in Flutter

  • How to use TextFormField with validation

  • How to switch between Login and Register screens

  • How to toggle password visibility

  • How to manage form state using StatefulWidget

  • Clean and professional UI design approach

This guide is practical and production-oriented.

Project Structure

 

Step 1: Setup Main File

main.dart

import 'package:flutter/material.dart';
import 'screens/login_screen.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Auth UI',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoginScreen(),
    );
  }
}

Step 2: Create Login Screen

login_screen.dart

import 'package:flutter/material.dart';
import 'home_screen.dart';
import 'signup_screen.dart';


class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {

  final _formKey = GlobalKey<FormState>();
  final emailController = TextEditingController();
  final passwordController = TextEditingController();

  bool isPasswordHidden = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Form(
          key: _formKey,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [

              Text(
                "Login",
                style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
              ),

              SizedBox(height: 30),

              // Email Field
              TextFormField(
                controller: emailController,
                decoration: InputDecoration(
                  labelText: "Email",
                  border: OutlineInputBorder(),
                ),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return "Please enter email";
                  }
                  if (!value.contains('@')) {
                    return "Enter valid email";
                  }
                  return null;
                },
              ),

              SizedBox(height: 20),

              // Password Field
              TextFormField(
                controller: passwordController,
                obscureText: isPasswordHidden,
                decoration: InputDecoration(
                  labelText: "Password",
                  border: OutlineInputBorder(),
                  suffixIcon: IconButton(
                    icon: Icon(isPasswordHidden
                        ? Icons.visibility
                        : Icons.visibility_off),
                    onPressed: () {
                      setState(() {
                        isPasswordHidden = !isPasswordHidden;
                      });
                    },
                  ),
                ),
                validator: (value) {
                  if (value == null || value.length < 6) {
                    return "Password must be at least 6 characters";
                  }
                  return null;
                },
              ),

              SizedBox(height: 25),

              ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (_) => HomeScreen()),
                    );
                  }
                },
                child: Text("Login"),
              ),

              SizedBox(height: 15),

              TextButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (_) => SignUpScreen()),
                  );
                },
                child: Text("Don't have an account? Sign Up"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Step 3: Create SignUp Screen

signup_screen.dart

import 'package:flutter/material.dart';

class SignUpScreen extends StatefulWidget {
  @override
  _SignUpScreenState createState() => _SignUpScreenState();
}

class _SignUpScreenState extends State<SignUpScreen> {

  final _formKey = GlobalKey<FormState>();

  final nameController = TextEditingController();
  final emailController = TextEditingController();
  final passwordController = TextEditingController();

  bool isPasswordHidden = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Form(
          key: _formKey,
          child: ListView(
            children: [

              SizedBox(height: 60),

              Text(
                "Sign Up",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
              ),

              SizedBox(height: 30),

              TextFormField(
                controller: nameController,
                decoration: InputDecoration(
                  labelText: "Full Name",
                  border: OutlineInputBorder(),
                ),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return "Enter your name";
                  }
                  return null;
                },
              ),

              SizedBox(height: 20),

              TextFormField(
                controller: emailController,
                decoration: InputDecoration(
                  labelText: "Email",
                  border: OutlineInputBorder(),
                ),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return "Enter email";
                  }
                  return null;
                },
              ),

              SizedBox(height: 20),

              TextFormField(
                controller: passwordController,
                obscureText: isPasswordHidden,
                decoration: InputDecoration(
                  labelText: "Password",
                  border: OutlineInputBorder(),
                  suffixIcon: IconButton(
                    icon: Icon(isPasswordHidden
                        ? Icons.visibility
                        : Icons.visibility_off),
                    onPressed: () {
                      setState(() {
                        isPasswordHidden = !isPasswordHidden;
                      });
                    },
                  ),
                ),
                validator: (value) {
                  if (value == null || value.length < 6) {
                    return "Password must be 6+ characters";
                  }
                  return null;
                },
              ),

              SizedBox(height: 25),

              ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState!.validate()) {
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text("Account Created Successfully")),
                    );
                    Navigator.pop(context);
                  }
                },
                child: Text("Register"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Step 4: Home Screen

import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Home")),
      body: Center(
        child: Text(
          "Welcome to Dashboard",
          style: TextStyle(fontSize: 22),
        ),
      ),
    );
  }
}

Key Concepts Used

1️⃣ StatefulWidget

Used to manage UI state like password visibility.

2️⃣ GlobalKey<FormState>

Used to validate form before submission.

3️⃣ TextEditingController

Captures user input from text fields.

4️⃣ Navigator

Handles screen transitions.

5️⃣ Form Validation

Ensures proper data before proceeding.


Real-World Enhancement (Production Ready)

For real applications, integrate authentication with:

  • Firebase Authentication

  • REST API (Node.js / Laravel backend)

  • JWT token handling

  • Secure storage

 

UI Improvement Tips

  • Use SingleChildScrollView to avoid overflow

  • Add social login buttons (Google, Facebook)

  • Add loading indicator

  • Add remember me checkbox

  • Use MediaQuery for responsive UI

  • Use FormField autovalidateMode

Common Interview Questions

  1. Difference between TextField and TextFormField?

  2. Why use GlobalKey<FormState>?

  3. Why Login screen is StatefulWidget?

  4. How to manage authentication state globally?

Conclusion

Creating a Login and SignUp page in Flutter is straightforward when you understand:

  • Form handling

  • State management

  • Navigation

  • Validation

This structure is scalable and can be extended with Firebase or backend authentication for production-level applications.

Flutter authentication UIFlutter Firebase authFlutter form validationFlutter login pageFlutter navigation exampleFlutter signup pageFlutter stateful widget exampleFlutter TextFormField validation
0
Author digitaldech

  • Website

Related Posts

MAD LAB 01: Routing and Multi-Screen Development in Flutter: Beginner Guide with Examples

February 25, 2026

Lesson 08: Advanced UI Design in Flutter: Elegant UI with Cards, ListTile & ListView (Complete Guide)

February 25, 2026

Lesson 07: Navigation in Flutter: Complete Guide to Navigator, Passing Data & Named Routes

February 22, 2026

MAD Assignment 01: Employ framework’s UI design approaches to create intuitive and adaptive UI design.

February 22, 2026

Write A Comment Cancel Reply

  • Newsletter

    Enter your email address below to subscribe to my newsletter

  • Latest Posts
    • MAD LAB 02: Login/SignUp Page in Flutter – Complete Authentication UI with Validation & Navigation
      March 4, 2026
    • DS LAB 06: Queue Data Structure in C++ with Real-Time Examples | Enqueue, Dequeue, Front & Rear Explained
      March 4, 2026
    • LAB 05: Stack Data Structure in C++ with Real-Life Examples | Push, Pop & Top Operations Explained
      March 3, 2026
  • Advert
  • Facebook
  • X (Twitter)
  • Instagram
  • Pinterest
  • Dribbble

© 2026 Design & Developed by Ashfaq Bhatti. All registered.

Top

    Type above and press Enter to search. Press Esc to cancel.