2025-12-30 15:02:51 +05:30

283 lines
12 KiB
Dart

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
class SignUpScreen extends StatefulWidget {
const SignUpScreen({super.key});
@override
State<SignUpScreen> createState() => _SignUpScreenState();
}
class _SignUpScreenState extends State<SignUpScreen> {
final _nameController = TextEditingController();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _mobileController = TextEditingController();
bool _isPasswordVisible = false;
@override
void dispose() {
_nameController.dispose();
_emailController.dispose();
_passwordController.dispose();
_mobileController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF0A0B17),
body: Stack(
children: [
// Background Blobs (Same as Login)
Positioned(
top: 180,
left: 50,
child: _buildGlowBlob(const Color(0xFF1D8BE0), 100),
),
Positioned(
top: 40,
left: 0,
child: _buildGlowBlob(const Color(0xFF6CB655), 60),
),
Positioned(
bottom: 140,
left: -40,
child: _buildGlowBlob(const Color(0xFFDB21D9), 100, height: 200),
),
Positioned(
top: 100,
right: 100,
child: _buildGlowBlob(const Color(0xFFF28F50), 100),
),
Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ClipRRect(
borderRadius: BorderRadius.circular(24),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
constraints: const BoxConstraints(maxWidth: 500),
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.05),
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.white.withOpacity(0.2)),
),
child: Consumer<AuthProvider>(
builder: (context, auth, child) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// Logo
const Icon(Icons.hub, size: 80, color: Colors.pinkAccent),
const SizedBox(height: 24),
Text(
"Create Account",
style: GoogleFonts.nunito(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Text(
"Join Social Buddy today!",
style: GoogleFonts.nunito(
color: Colors.white.withOpacity(0.7),
fontSize: 16,
),
),
const SizedBox(height: 32),
if (auth.error != null)
Container(
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
border: Border.all(color: Colors.red.withOpacity(0.3)),
borderRadius: BorderRadius.circular(8),
),
child: Text(
auth.error!,
style: const TextStyle(color: Colors.redAccent),
),
),
// Name
TextFormField(
controller: _nameController,
style: const TextStyle(color: Colors.white),
decoration: _inputDecoration("Full Name", Icons.person_outline),
),
const SizedBox(height: 16),
// Email
TextFormField(
controller: _emailController,
style: const TextStyle(color: Colors.white),
decoration: _inputDecoration("Email Address", Icons.email_outlined),
),
const SizedBox(height: 16),
// Password
TextFormField(
controller: _passwordController,
obscureText: !_isPasswordVisible,
style: const TextStyle(color: Colors.white),
decoration: _inputDecoration("Password", Icons.lock_outline).copyWith(
suffixIcon: IconButton(
icon: Icon(
_isPasswordVisible ? Icons.visibility_off : Icons.visibility,
color: Colors.white70,
),
onPressed: () {
setState(() {
_isPasswordVisible = !_isPasswordVisible;
});
},
),
),
),
const SizedBox(height: 16),
// Mobile
TextFormField(
controller: _mobileController,
style: const TextStyle(color: Colors.white),
decoration: _inputDecoration("Mobile Number", Icons.phone_android_outlined),
),
const SizedBox(height: 24),
// Sign Up Button
SizedBox(
width: double.infinity,
height: 50,
child: Container(
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF2563EB), Color(0xFFEC4899)],
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: const Color(0xFFEC4899).withOpacity(0.3),
blurRadius: 12,
offset: const Offset(0, 4),
),
],
),
child: ElevatedButton(
onPressed: auth.isLoading
? null
: () async {
final success = await auth.signup({
'name': _nameController.text,
'email': _emailController.text,
'password': _passwordController.text,
'mobileNumber': _mobileController.text,
});
if (success && mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Account created! Please Login.")),
);
Navigator.pop(context); // Go back to Login
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: auth.isLoading
? const CircularProgressIndicator(color: Colors.white)
: const Text(
"SIGN UP",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 1,
),
),
),
),
),
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Already have an account? ", style: TextStyle(color: Colors.white.withOpacity(0.6))),
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: const Text("SIGN IN", style: TextStyle(color: Colors.blueAccent, fontWeight: FontWeight.bold)),
)
],
),
],
);
},
),
),
),
),
),
),
],
),
);
}
Widget _buildGlowBlob(Color color, double width, {double? height}) {
return Container(
width: width,
height: height ?? width,
decoration: BoxDecoration(
color: color.withOpacity(0.4),
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: color.withOpacity(0.6),
blurRadius: 100,
spreadRadius: 20,
),
],
),
);
}
InputDecoration _inputDecoration(String label, IconData icon) {
return InputDecoration(
hintText: label,
hintStyle: TextStyle(color: Colors.white.withOpacity(0.5)),
prefixIcon: Icon(icon, color: Colors.white70),
filled: true,
fillColor: const Color(0xFF070D1E).withOpacity(0.7),
contentPadding: const EdgeInsets.symmetric(vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white.withOpacity(0.15)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white.withOpacity(0.15)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white.withOpacity(0.3)),
),
);
}
}