import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/auth_provider.dart'; import '../../dashboard/presentation/dashboard_screen.dart'; class OtpScreen extends ConsumerStatefulWidget { final String email; const OtpScreen({super.key, required this.email}); @override ConsumerState createState() => _OtpScreenState(); } class _OtpScreenState extends ConsumerState { final otpController = TextEditingController(); Future verify() async { final otp = otpController.text.trim(); if (otp.isEmpty) return; final success = await ref.read(authControllerProvider.notifier).verifyOtp(widget.email, otp); if (success && mounted) { Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (_) => const DashboardScreen()), (route) => false); } } @override Widget build(BuildContext context) { ref.listen>(authControllerProvider, (previous, next) { if (next.hasError) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Error: ${next.error}')), ); } }); final state = ref.watch(authControllerProvider); final isLoading = state.isLoading; return Scaffold( appBar: AppBar(backgroundColor: Colors.transparent, elevation: 0), body: SafeArea( child: Padding( padding: const EdgeInsets.all(24.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( 'Verify Email', style: Theme.of(context).textTheme.displayLarge, textAlign: TextAlign.center, ), const SizedBox(height: 8), Text( 'Enter the 6-digit OTP sent to ${widget.email}', style: Theme.of(context).textTheme.bodyMedium, textAlign: TextAlign.center, ), const SizedBox(height: 48), TextField( controller: otpController, keyboardType: TextInputType.number, textAlign: TextAlign.center, maxLength: 6, style: const TextStyle(fontSize: 24, letterSpacing: 8, fontWeight: FontWeight.bold, color: Color(0xFF6C63FF)), decoration: InputDecoration( hintText: '000000', hintStyle: TextStyle(letterSpacing: 8, color: Colors.grey.shade400), filled: true, fillColor: Colors.grey.shade100, contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20), border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none), focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Color(0xFF6C63FF), width: 2)), ), ), const SizedBox(height: 32), ElevatedButton( onPressed: isLoading ? null : verify, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF6C63FF), foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 16), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), elevation: 0, ), child: isLoading ? const SizedBox(height: 20, width: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : const Text('Verify', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), ), ], ), ), ), ); } }