Flutter + MySQL Authentication App | Full Login & Register System with PHP Backend

 Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡

























Features:

✔ Use "Search Description" → Add 150-character SEO text
✔ Enable "Custom Robots.txt" (optional)
✔ Add images: Flutter logo, MySQL logo, app UI screenshots
✔ Insert code blocks for Flutter, PHP, SQL
✔ Add YouTube video embed for extra SEO boost


Code :


Folder Structure :

 * flutter_mysql_auth_app

main.dart

pubspec.yaml 

* htdocs

mysql_auth_backend 

db_connect.php

login.php

register.php

sql 


1) main.dart


import 'package:flutter/material.dart';

import 'package:http/http.dart' as http;

import 'dart:convert';


void main() {

  runApp(MySQLAuthApp());

}


class MySQLAuthApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      debugShowCheckedModeBanner: false,

      title: 'Fuzzu MySQL Auth',

      theme: ThemeData(

        colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),

        useMaterial3: true,

      ),

      home: AuthScreen(),

    );

  }

}


class AuthScreen extends StatefulWidget {

  @override

  State<AuthScreen> createState() => _AuthScreenState();

}


class _AuthScreenState extends State<AuthScreen> {

  final email = TextEditingController();

  final pass = TextEditingController();

  bool isLogin = true;

  bool loading = false;


  Future<void> submit() async {

    setState(() => loading = true);


    final url = isLogin

        ? "http://localhost/mysql_auth_backend/login.php"

        : "http://localhost/mysql_auth_backend/register.php";


    final response = await http.post(

      Uri.parse(url),

      headers: {"Content-Type": "application/json"},

      body: jsonEncode({

        "email": email.text,

        "password": pass.text,

      }),

    );


    final data = jsonDecode(response.body);

    setState(() => loading = false);


    if (data["status"] == "success") {

      Navigator.push(

        context,

        MaterialPageRoute(

          builder: (_) => Dashboard(email: email.text),

        ),

      );

    } else {

      ScaffoldMessenger.of(context).showSnackBar(

        SnackBar(content: Text(data["message"])),

      );

    }

  }


  @override

  Widget build(BuildContext context) {

    return Scaffold(

      backgroundColor: Colors.grey.shade200,

      body: Center(

        child: Container(

          width: 380,

          padding: EdgeInsets.all(24),

          decoration: BoxDecoration(

            color: Colors.white,

            borderRadius: BorderRadius.circular(25),

            boxShadow: [

              BoxShadow(

                blurRadius: 20,

                color: Colors.black12,

                offset: Offset(0, 8),

              )

            ],

          ),

          child: Column(

            mainAxisSize: MainAxisSize.min,

            children: [

              AnimatedSwitcher(

                duration: Duration(milliseconds: 300),

                child: Text(

                  isLogin ? "Login" : "Register",

                  key: ValueKey(isLogin),

                  style: TextStyle(

                    fontSize: 32,

                    fontWeight: FontWeight.bold,

                    color: Colors.indigo,

                  ),

                ),

              ),

              SizedBox(height: 20),

              TextField(

                controller: email,

                decoration: InputDecoration(

                  labelText: "Email",

                  prefixIcon: Icon(Icons.email),

                  border: OutlineInputBorder(

                    borderRadius: BorderRadius.circular(15),

                  ),

                ),

              ),

              SizedBox(height: 15),

              TextField(

                controller: pass,

                obscureText: true,

                decoration: InputDecoration(

                  labelText: "Password",

                  prefixIcon: Icon(Icons.lock),

                  border: OutlineInputBorder(

                    borderRadius: BorderRadius.circular(15),

                  ),

                ),

              ),

              SizedBox(height: 25),

              loading

                  ? CircularProgressIndicator(color: Colors.indigo)

                  : ElevatedButton(

                      onPressed: submit,

                      style: ElevatedButton.styleFrom(

                        backgroundColor: Colors.indigo,

                        foregroundColor: Colors.white,

                        padding: EdgeInsets.symmetric(

                            horizontal: 60, vertical: 15),

                        shape: RoundedRectangleBorder(

                          borderRadius: BorderRadius.circular(14),

                        ),

                      ),

                      child: Text(

                        isLogin ? "Login" : "Register",

                        style: TextStyle(fontSize: 18),

                      ),

                    ),

              TextButton(

                onPressed: () => setState(() => isLogin = !isLogin),

                child: Text(

                  isLogin

                      ? "Create new account"

                      : "Already have an account?",

                  style: TextStyle(color: Colors.indigo),

                ),

              ),

            ],

          ),

        ),

      ),

    );

  }

}


class Dashboard extends StatelessWidget {

  final String email;

  Dashboard({required this.email});


  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        title: Text("Dashboard"),

        backgroundColor: Colors.indigo,

        actions: [

          IconButton(

            icon: Icon(Icons.logout),

            onPressed: () {

              Navigator.pop(context);

            },

          )

        ],

      ),

      body: Center(

        child: Text(

          "Welcome $email πŸ‘‹",

          style: TextStyle(

            fontSize: 25,

            fontWeight: FontWeight.bold,

          ),

        ),

      ),

    );

  }

}


2) pubspec.yaml


dependencies:

  flutter:

    sdk: flutter

  http: ^1.2.1

  flutter_material_color_picker: ^1.1.0


3) db_connect.php


<?php

$conn = new mysqli("localhost", "root", "", "flutter_auth");

if ($conn->connect_error) {

  die("Connection failed: " . $conn->connect_error);

}

?>

4) login.php


<?php
include 'db_connect.php';
$data = json_decode(file_get_contents("php://input"));
$email = $data->email;
$password = $data->password;

$user = $conn->query("SELECT * FROM users WHERE email='$email' AND password='$password'");
if ($user->num_rows > 0) {
  echo json_encode(["status" => "success", "message" => "Login successful"]);
} else {
  echo json_encode(["status" => "error", "message" => "Invalid credentials"]);
}
?>

5) register.php

<?php
include 'db_connect.php';
$data = json_decode(file_get_contents("php://input"));
$email = $data->email;
$password = $data->password;

$check = $conn->query("SELECT * FROM users WHERE email='$email'");
if ($check->num_rows > 0) {
  echo json_encode(["status" => "error", "message" => "User already exists"]);
} else {
  $conn->query("INSERT INTO users (email,password) VALUES('$email','$password')");
  echo json_encode(["status" => "success", "message" => "Registered successfully"]);
}
?>

6) sql

CREATE DATABASE flutter_auth;
USE flutter_auth;

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(100) NOT NULL,
  password VARCHAR(100) NOT NULL
);

 

Comments

Popular posts from this blog

Is This News Real or Fake? πŸ€– AI Exposes the Truth | FuzzuTech Python App Demo

🚨 Python Intrusion Detection System (IDS) – Real-Time ML + Tkinter GUI Project | FuzzuTech

Educational File Encryptor GUI (Python AES Project) | FuzzuTech