mobile_team/lib/screens/login_screen.dart
2026-04-16 15:06:41 +05:30

190 lines
6.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _formKey = GlobalKey<FormState>();
void _login() async {
if (_formKey.currentState!.validate()) {
try {
await context.read<AuthProvider>().login(
_emailController.text.trim(),
_passwordController.text.trim(),
);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Login failed: ${e.toString()}'),
backgroundColor: Colors.red,
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.all(20),
),
);
}
}
}
}
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final bool isLoading = context.watch<AuthProvider>().isLoading;
return Scaffold(
body: Stack(
children: [
// Background Gradient
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF6366F1), Color(0xFF4338CA)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
),
// Decorative circles
Positioned(
top: -100,
right: -100,
child: CircleAvatar(
radius: 150,
backgroundColor: Colors.white.withOpacity(0.1),
),
),
Positioned(
bottom: -50,
left: -50,
child: CircleAvatar(
radius: 100,
backgroundColor: Colors.white.withOpacity(0.05),
),
),
Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(28.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.rocket_launch_rounded, size: 72, color: Colors.white),
const SizedBox(height: 24),
const Text(
'ANTIGRAVITY',
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
letterSpacing: 2.0,
),
),
const Text(
'TEAM COLLABORATION',
style: TextStyle(
color: Colors.white70,
fontSize: 12,
fontWeight: FontWeight.bold,
letterSpacing: 1.5,
),
),
const SizedBox(height: 48),
Container(
padding: const EdgeInsets.all(28),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 20,
offset: const Offset(0, 10),
),
],
),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Welcome Back',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF1E293B),
),
),
const SizedBox(height: 8),
Text(
'Enter your credentials to continue',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade500,
),
),
const SizedBox(height: 32),
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Email Address',
prefixIcon: Icon(Icons.alternate_email_rounded, size: 20),
),
validator: (value) =>
(value == null || !value.contains('@')) ? 'Enter a valid email' : null,
),
const SizedBox(height: 16),
TextFormField(
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
prefixIcon: Icon(Icons.lock_person_rounded, size: 20),
),
validator: (value) =>
(value == null || value.length < 6) ? 'Enter at least 6 characters' : null,
),
const SizedBox(height: 32),
isLoading
? const Center(child: CircularProgressIndicator())
: ElevatedButton(
onPressed: _login,
child: const Text('SIGN IN TO DASHBOARD'),
),
],
),
),
),
const SizedBox(height: 32),
const Text(
'Need an account? Contact your lead.',
style: TextStyle(color: Colors.white70, fontSize: 13),
),
],
),
),
),
],
),
);
}
}