tasktracker/lib/screens/login_screen.dart
2025-10-07 21:54:06 +05:30

226 lines
7.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../widgets/oauth_button.dart';
import '../widgets/custom_text_field.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
bool _isPasswordVisible = false;
bool _isLoading = false;
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
void _handleLogin() {
if (_formKey.currentState!.validate()) {
setState(() {
_isLoading = true;
});
// TODO: Implement Appwrite login logic here
// For now, just simulate loading
Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
setState(() {
_isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Login functionality will be implemented with Appwrite')),
);
}
});
}
}
void _handleOAuthLogin(String provider) {
// TODO: Implement OAuth login with Appwrite
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('$provider OAuth login will be implemented with Appwrite')),
);
}
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 24),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Email Field
CustomTextField(
controller: _emailController,
labelText: 'Email',
hintText: 'Enter your email',
keyboardType: TextInputType.emailAddress,
prefixIcon: Icons.email_outlined,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your email';
}
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
return 'Please enter a valid email';
}
return null;
},
),
const SizedBox(height: 16),
// Password Field
CustomTextField(
controller: _passwordController,
labelText: 'Password',
hintText: 'Enter your password',
obscureText: !_isPasswordVisible,
prefixIcon: Icons.lock_outlined,
suffixIcon: IconButton(
icon: Icon(
_isPasswordVisible ? Icons.visibility_off : Icons.visibility,
),
onPressed: () {
setState(() {
_isPasswordVisible = !_isPasswordVisible;
});
},
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your password';
}
if (value.length < 6) {
return 'Password must be at least 6 characters';
}
return null;
},
),
const SizedBox(height: 8),
// Forgot Password
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
// TODO: Implement forgot password
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Forgot password functionality will be implemented')),
);
},
child: Text(
'Forgot Password?',
style: GoogleFonts.poppins(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w500,
),
),
),
),
const SizedBox(height: 24),
// Login Button
ElevatedButton(
onPressed: _isLoading ? null : _handleLogin,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
),
child: _isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
'Login',
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
const SizedBox(height: 32),
// Divider
Row(
children: [
Expanded(
child: Divider(
color: Colors.grey[300],
thickness: 1,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Or continue with',
style: GoogleFonts.poppins(
color: Colors.grey[600],
fontSize: 14,
),
),
),
Expanded(
child: Divider(
color: Colors.grey[300],
thickness: 1,
),
),
],
),
const SizedBox(height: 24),
// OAuth Buttons
OAuthButton(
provider: 'Google',
icon: Icons.g_mobiledata,
onPressed: () => _handleOAuthLogin('Google'),
),
const SizedBox(height: 12),
OAuthButton(
provider: 'Facebook',
icon: Icons.facebook,
onPressed: () => _handleOAuthLogin('Facebook'),
),
const SizedBox(height: 12),
OAuthButton(
provider: 'GitHub',
icon: Icons.code,
onPressed: () => _handleOAuthLogin('GitHub'),
),
],
),
),
);
}
}