MIF_E31231033/lib/screens/auth/forgot_password_screen.dart

132 lines
3.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../services/auth_service.dart';
import 'verify_reset_otp_screen.dart';
class ForgotPasswordScreen extends StatefulWidget {
const ForgotPasswordScreen({super.key});
@override
State<ForgotPasswordScreen> createState() => _ForgotPasswordScreenState();
}
class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
final emailController = TextEditingController();
bool _isLoading = false;
Future<void> _sendOtp() async {
final email = emailController.text.trim();
if (email.isEmpty || !email.contains('@')) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Masukkan email yang valid")),
);
return;
}
setState(() {
_isLoading = true;
});
final result = await AuthService.forgotPassword(email);
print("RESULT OTP: $result");
setState(() {
_isLoading = false;
});
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(result['message'])));
if (result['success'] == true) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VerifyResetOtpScreen(email: email),
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF2F5BEA),
appBar: AppBar(
backgroundColor: const Color(0xFF2F5BEA),
elevation: 0,
iconTheme: const IconThemeData(color: Colors.white),
title: const Text(
"Forgot Password",
style: TextStyle(color: Colors.white),
),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.lock_reset, size: 80, color: Colors.white),
const SizedBox(height: 20),
const Text(
"Masukkan email untuk menerima kode OTP reset password.",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 16),
),
const SizedBox(height: 30),
TextField(
controller: emailController,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: "Email",
hintStyle: const TextStyle(color: Colors.white70),
prefixIcon: const Icon(Icons.email, color: Colors.white),
filled: true,
fillColor: Colors.white.withOpacity(0.2),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide.none,
),
),
),
const SizedBox(height: 30),
ElevatedButton(
onPressed: _isLoading ? null : _sendOtp,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: const Color(0xFF2F5BEA),
minimumSize: const Size(double.infinity, 55),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
child:
_isLoading
? const CircularProgressIndicator(
color: Color(0xFF2F5BEA),
)
: const Text(
"SEND OTP",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
),
),
),
);
}
}