fix: v2.0.4+24 — login fixes, signup toggle, forgot-password, guest SnackBar, Google OAuth
- Google Sign-In: wire serverClientId (639347358523-mtkm...apps.googleusercontent.com) so idToken is returned on Android - Email login: raise timeout 10s→25s, add single retry on SocketException/TimeoutException - Forgot Password: real glassmorphism bottom sheet with safe-degrade SnackBar (endpoint missing on backend) - Create Account: same-page AnimatedSwitcher toggle with glassmorphism signup form; delete old RegisterScreen - Desktop parity: DesktopLoginScreen same-page toggle; delete DesktopRegisterScreen - Guest mode: remove ScaffoldMessenger SnackBar from HomeScreen outer catch (inner _safe wrappers already return []) - LoginScreen: clearSnackBars() on postFrameCallback to prevent carried-over SnackBars from prior screens - ProGuard: add Google Sign-In + OkHttp keep rules - Version bump: 2.0.0+20 → 2.0.4+24; settings _appVersion → 2.0.4 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,9 +15,23 @@ class DesktopLoginScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTickerProviderStateMixin {
|
||||
// Login controllers
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
|
||||
// Signup controllers
|
||||
final TextEditingController _signupEmailCtrl = TextEditingController();
|
||||
final TextEditingController _signupPhoneCtrl = TextEditingController();
|
||||
final TextEditingController _signupPassCtrl = TextEditingController();
|
||||
final TextEditingController _signupConfirmCtrl = TextEditingController();
|
||||
String? _signupDistrict;
|
||||
|
||||
static const _districts = [
|
||||
'Thiruvananthapuram', 'Kollam', 'Pathanamthitta', 'Alappuzha',
|
||||
'Kottayam', 'Idukki', 'Ernakulam', 'Thrissur', 'Palakkad',
|
||||
'Malappuram', 'Kozhikode', 'Wayanad', 'Kannur', 'Kasaragod',
|
||||
];
|
||||
|
||||
final AuthService _auth = AuthService();
|
||||
|
||||
AnimationController? _controller;
|
||||
@@ -31,13 +45,18 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
final Curve _curve = Curves.easeInOutCubic;
|
||||
|
||||
bool _isAnimating = false;
|
||||
bool _loading = false; // network loading flag
|
||||
bool _loading = false;
|
||||
bool _isSignupMode = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller?.dispose();
|
||||
_emailCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
_signupEmailCtrl.dispose();
|
||||
_signupPhoneCtrl.dispose();
|
||||
_signupPassCtrl.dispose();
|
||||
_signupConfirmCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -52,7 +71,6 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
_leftTextOpacityAnim = Tween<double>(begin: 1.0, end: 0.0).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: const Interval(0.0, 0.35, curve: Curves.easeOut)),
|
||||
);
|
||||
|
||||
_formOpacityAnim = Tween<double>(begin: 1.0, end: 0.0).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: const Interval(0.0, 0.55, curve: Curves.easeOut)),
|
||||
);
|
||||
@@ -68,9 +86,7 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
Future<void> _performLoginFlow(double initialLeftWidth) async {
|
||||
if (_isAnimating || _loading) return;
|
||||
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
setState(() => _loading = true);
|
||||
|
||||
final email = _emailCtrl.text.trim();
|
||||
final password = _passCtrl.text;
|
||||
@@ -87,14 +103,9 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
}
|
||||
|
||||
try {
|
||||
// Capture user model returned by AuthService (AuthService already saves prefs)
|
||||
await _auth.login(email, password);
|
||||
|
||||
// on success run opening animation
|
||||
await _startCollapseAnimation(initialLeftWidth);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.of(context).pushReplacement(PageRouteBuilder(
|
||||
pageBuilder: (context, a1, a2) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true),
|
||||
transitionDuration: Duration.zero,
|
||||
@@ -102,24 +113,292 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = userFriendlyError(e);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(userFriendlyError(e))));
|
||||
setState(() => _isAnimating = false);
|
||||
} finally {
|
||||
if (mounted) setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _openRegister() {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const DesktopRegisterScreen()));
|
||||
Future<void> _performSignupFlow(double initialLeftWidth) async {
|
||||
if (_isAnimating || _loading) return;
|
||||
|
||||
final email = _signupEmailCtrl.text.trim();
|
||||
final phone = _signupPhoneCtrl.text.trim();
|
||||
final pass = _signupPassCtrl.text;
|
||||
final confirm = _signupConfirmCtrl.text;
|
||||
|
||||
if (email.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter email')));
|
||||
return;
|
||||
}
|
||||
if (phone.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter phone number')));
|
||||
return;
|
||||
}
|
||||
if (pass.length < 6) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Password must be at least 6 characters')));
|
||||
return;
|
||||
}
|
||||
if (pass != confirm) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Passwords do not match')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _loading = true);
|
||||
|
||||
try {
|
||||
await _auth.register(
|
||||
email: email,
|
||||
phoneNumber: phone,
|
||||
password: pass,
|
||||
district: _signupDistrict,
|
||||
);
|
||||
await _startCollapseAnimation(initialLeftWidth);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pushReplacement(PageRouteBuilder(
|
||||
pageBuilder: (context, a1, a2) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true),
|
||||
transitionDuration: Duration.zero,
|
||||
reverseTransitionDuration: Duration.zero,
|
||||
));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(userFriendlyError(e))));
|
||||
setState(() => _isAnimating = false);
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openForgotPasswordDialog() async {
|
||||
final emailCtrl = TextEditingController(text: _emailCtrl.text.trim());
|
||||
bool submitting = false;
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (ctx, setDialog) {
|
||||
return AlertDialog(
|
||||
title: const Text('Forgot Password'),
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text("Enter your email and we'll send reset instructions."),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: emailCtrl,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
labelText: 'Email',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(ctx).pop(), child: const Text('Cancel')),
|
||||
ElevatedButton(
|
||||
onPressed: submitting
|
||||
? null
|
||||
: () async {
|
||||
final email = emailCtrl.text.trim();
|
||||
if (email.isEmpty) return;
|
||||
setDialog(() => submitting = true);
|
||||
try {
|
||||
await _auth.forgotPassword(email);
|
||||
} catch (_) {
|
||||
// safe-degrade
|
||||
}
|
||||
if (!ctx.mounted) return;
|
||||
Navigator.of(ctx).pop();
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("If that email is registered, we've sent reset instructions."),
|
||||
duration: Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: submitting
|
||||
? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('Send reset link'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
emailCtrl.dispose();
|
||||
}
|
||||
|
||||
Widget _buildLoginFields(double safeInitialWidth) {
|
||||
return Column(
|
||||
key: const ValueKey('login'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('Sign In', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
const SizedBox(height: 6),
|
||||
const Text('Please enter your details to continue', textAlign: TextAlign.center, style: TextStyle(color: Colors.black54)),
|
||||
const SizedBox(height: 22),
|
||||
TextField(
|
||||
controller: _emailCtrl,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
labelText: 'Email Address',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _passCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.lock),
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
const Text('Remember me'),
|
||||
]),
|
||||
TextButton(onPressed: _openForgotPasswordDialog, child: const Text('Forgot Password?')),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isAnimating || _loading) ? null : () => _performLoginFlow(safeInitialWidth),
|
||||
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
|
||||
child: (_isAnimating || _loading)
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('Sign In', style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => setState(() => _isSignupMode = true),
|
||||
child: const Text("Don't have an account? Register"),
|
||||
),
|
||||
TextButton(onPressed: () {}, child: const Text('Contact support')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
AuthGuard.setGuest(true);
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (_) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true)),
|
||||
(route) => false,
|
||||
);
|
||||
},
|
||||
child: const Text('Continue as Guest'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSignupFields(double safeInitialWidth) {
|
||||
return Column(
|
||||
key: const ValueKey('signup'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('Create Account', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
const SizedBox(height: 6),
|
||||
const Text('Fill in your details to get started', textAlign: TextAlign.center, style: TextStyle(color: Colors.black54)),
|
||||
const SizedBox(height: 22),
|
||||
TextField(
|
||||
controller: _signupEmailCtrl,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
labelText: 'Email Address',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _signupPhoneCtrl,
|
||||
keyboardType: TextInputType.phone,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.phone),
|
||||
labelText: 'Phone Number',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _signupDistrict,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.location_on),
|
||||
labelText: 'District (optional)',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
items: _districts.map((d) => DropdownMenuItem(value: d, child: Text(d))).toList(),
|
||||
onChanged: (v) => setState(() => _signupDistrict = v),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _signupPassCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.lock),
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _signupConfirmCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
labelText: 'Confirm Password',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isAnimating || _loading) ? null : () => _performSignupFlow(safeInitialWidth),
|
||||
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
|
||||
child: (_isAnimating || _loading)
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('Create Account', style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Center(
|
||||
child: TextButton(
|
||||
onPressed: () => setState(() => _isSignupMode = false),
|
||||
child: const Text('Already have an account? Sign in'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenW = MediaQuery.of(context).size.width;
|
||||
|
||||
final double safeInitialWidth = (screenW * 0.45).clamp(360.0, screenW * 0.65);
|
||||
final bool animAvailable = _controller != null && _leftWidthAnim != null;
|
||||
final Listenable animation = _controller ?? AlwaysStoppedAnimation(0.0);
|
||||
@@ -139,7 +418,6 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
Container(
|
||||
width: leftWidth,
|
||||
height: double.infinity,
|
||||
// color: const Color(0xFF0B63D6),
|
||||
decoration: AppDecoration.blueGradient,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 28),
|
||||
child: Opacity(
|
||||
@@ -150,11 +428,16 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
const SizedBox(height: 4),
|
||||
const Text('EVENTIFY', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w800, fontSize: 22)),
|
||||
const Spacer(),
|
||||
const Text('Welcome Back!', style: TextStyle(color: Colors.white, fontSize: 34, fontWeight: FontWeight.bold)),
|
||||
Text(
|
||||
_isSignupMode ? 'Join Eventify!' : 'Welcome Back!',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 34, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Sign in to access your dashboard, manage events, and stay connected.',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
Text(
|
||||
_isSignupMode
|
||||
? 'Create your account to discover events, book tickets, and connect with your community.'
|
||||
: 'Sign in to access your dashboard, manage events, and stay connected.',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
const Spacer(flex: 2),
|
||||
Opacity(
|
||||
@@ -168,7 +451,6 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Transform.translate(
|
||||
offset: Offset(formOffset, 0),
|
||||
@@ -178,85 +460,20 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
color: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 36),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28.0, vertical: 28.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('Sign In', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
const SizedBox(height: 6),
|
||||
const Text('Please enter your details to continue', textAlign: TextAlign.center, style: TextStyle(color: Colors.black54)),
|
||||
const SizedBox(height: 22),
|
||||
TextField(
|
||||
controller: _emailCtrl,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
labelText: 'Email Address',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _passCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.lock),
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
const Text('Remember me')
|
||||
]),
|
||||
TextButton(onPressed: () {}, child: const Text('Forgot Password?'))
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isAnimating || _loading)
|
||||
? null
|
||||
: () {
|
||||
final double initial = safeInitialWidth;
|
||||
_performLoginFlow(initial);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
|
||||
child: (_isAnimating || _loading)
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('Sign In', style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(onPressed: _openRegister, child: const Text("Don't have an account? Register")),
|
||||
TextButton(onPressed: () {}, child: const Text('Contact support')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
AuthGuard.setGuest(true);
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (_) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true)),
|
||||
(route) => false,
|
||||
);
|
||||
},
|
||||
child: const Text('Continue as Guest'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
child: SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28.0, vertical: 28.0),
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 260),
|
||||
child: _isSignupMode
|
||||
? _buildSignupFields(safeInitialWidth)
|
||||
: _buildLoginFields(safeInitialWidth),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -274,113 +491,3 @@ class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTick
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DesktopRegisterScreen extends StatefulWidget {
|
||||
const DesktopRegisterScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DesktopRegisterScreen> createState() => _DesktopRegisterScreenState();
|
||||
}
|
||||
|
||||
class _DesktopRegisterScreenState extends State<DesktopRegisterScreen> {
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _phoneCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
final TextEditingController _confirmCtrl = TextEditingController();
|
||||
final AuthService _auth = AuthService();
|
||||
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_phoneCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
_confirmCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _performRegister() async {
|
||||
final email = _emailCtrl.text.trim();
|
||||
final phone = _phoneCtrl.text.trim();
|
||||
final pass = _passCtrl.text;
|
||||
final confirm = _confirmCtrl.text;
|
||||
|
||||
if (email.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter email')));
|
||||
return;
|
||||
}
|
||||
if (phone.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter phone number')));
|
||||
return;
|
||||
}
|
||||
if (pass.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter password')));
|
||||
return;
|
||||
}
|
||||
if (pass != confirm) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Passwords do not match')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _loading = true);
|
||||
|
||||
try {
|
||||
await _auth.register(
|
||||
email: email,
|
||||
phoneNumber: phone,
|
||||
password: pass,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true)));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = userFriendlyError(e);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Register')),
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(controller: _emailCtrl, decoration: const InputDecoration(labelText: 'Email')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _phoneCtrl, decoration: const InputDecoration(labelText: 'Phone')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _passCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Password')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _confirmCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Confirm password')),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
ElevatedButton(onPressed: _loading ? null : _performRegister, child: _loading ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : const Text('Register')),
|
||||
const SizedBox(width: 12),
|
||||
OutlinedButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel')),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user