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

311 lines
10 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 RegisterScreen extends StatefulWidget {
const RegisterScreen({super.key});
@override
State<RegisterScreen> createState() => _RegisterScreenState();
}
class _RegisterScreenState extends State<RegisterScreen> {
final _formKey = GlobalKey<FormState>();
final _nameController = TextEditingController();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _confirmPasswordController = TextEditingController();
bool _isPasswordVisible = false;
bool _isConfirmPasswordVisible = false;
bool _isLoading = false;
bool _agreeToTerms = false;
@override
void dispose() {
_nameController.dispose();
_emailController.dispose();
_passwordController.dispose();
_confirmPasswordController.dispose();
super.dispose();
}
void _handleRegister() {
if (_formKey.currentState!.validate() && _agreeToTerms) {
setState(() {
_isLoading = true;
});
// TODO: Implement Appwrite registration 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('Registration functionality will be implemented with Appwrite')),
);
}
});
} else if (!_agreeToTerms) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Please agree to the terms and conditions')),
);
}
}
void _handleOAuthRegister(String provider) {
// TODO: Implement OAuth registration with Appwrite
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('$provider OAuth registration 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: [
// Name Field
CustomTextField(
controller: _nameController,
labelText: 'Full Name',
hintText: 'Enter your full name',
prefixIcon: Icons.person_outlined,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your full name';
}
if (value.length < 2) {
return 'Name must be at least 2 characters';
}
return null;
},
),
const SizedBox(height: 16),
// 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 < 8) {
return 'Password must be at least 8 characters';
}
if (!RegExp(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)').hasMatch(value)) {
return 'Password must contain uppercase, lowercase, and number';
}
return null;
},
),
const SizedBox(height: 16),
// Confirm Password Field
CustomTextField(
controller: _confirmPasswordController,
labelText: 'Confirm Password',
hintText: 'Confirm your password',
obscureText: !_isConfirmPasswordVisible,
prefixIcon: Icons.lock_outlined,
suffixIcon: IconButton(
icon: Icon(
_isConfirmPasswordVisible ? Icons.visibility_off : Icons.visibility,
),
onPressed: () {
setState(() {
_isConfirmPasswordVisible = !_isConfirmPasswordVisible;
});
},
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please confirm your password';
}
if (value != _passwordController.text) {
return 'Passwords do not match';
}
return null;
},
),
const SizedBox(height: 16),
// Terms and Conditions
Row(
children: [
Checkbox(
value: _agreeToTerms,
onChanged: (value) {
setState(() {
_agreeToTerms = value ?? false;
});
},
activeColor: Theme.of(context).primaryColor,
),
Expanded(
child: RichText(
text: TextSpan(
style: GoogleFonts.poppins(
color: Colors.grey[600],
fontSize: 14,
),
children: [
const TextSpan(text: 'I agree to the '),
TextSpan(
text: 'Terms and Conditions',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w600,
),
),
const TextSpan(text: ' and '),
TextSpan(
text: 'Privacy Policy',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
],
),
const SizedBox(height: 24),
// Register Button
ElevatedButton(
onPressed: _isLoading ? null : _handleRegister,
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(
'Create Account',
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: () => _handleOAuthRegister('Google'),
),
const SizedBox(height: 12),
OAuthButton(
provider: 'Facebook',
icon: Icons.facebook,
onPressed: () => _handleOAuthRegister('Facebook'),
),
const SizedBox(height: 12),
OAuthButton(
provider: 'GitHub',
icon: Icons.code,
onPressed: () => _handleOAuthRegister('GitHub'),
),
],
),
),
);
}
}