151 lines
5.6 KiB
Dart
151 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
|
|
class ForgotPasswordPage extends StatefulWidget {
|
|
@override
|
|
_ForgotPasswordPageState createState() => _ForgotPasswordPageState();
|
|
}
|
|
|
|
class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
|
|
final TextEditingController emailController = TextEditingController();
|
|
bool isLoading = false;
|
|
|
|
Future<void> sendPasswordResetEmail(String email) async {
|
|
setState(() {
|
|
isLoading = true;
|
|
});
|
|
|
|
try {
|
|
await FirebaseAuth.instance.sendPasswordResetEmail(email: email);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Link reset password dikirim ke $email')),
|
|
);
|
|
} on FirebaseAuthException catch (e) {
|
|
String message = 'Terjadi kesalahan';
|
|
if (e.code == 'user-not-found') {
|
|
message = 'Email tidak ditemukan';
|
|
}
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(message)),
|
|
);
|
|
} finally {
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
Color(0xFFB3E5FC), // biru pastel muda
|
|
Color(0xFFE1F5FE), // biru pastel pucat
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.lock_reset, size: 80, color: Colors.blueGrey[800]),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
'Reset Password',
|
|
style: TextStyle(
|
|
fontSize: 26,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.blueGrey[800],
|
|
),
|
|
),
|
|
const SizedBox(height: 30),
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.95),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.blueGrey.withOpacity(0.1),
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
TextField(
|
|
controller: emailController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
decoration: InputDecoration(
|
|
prefixIcon: Icon(Icons.email, color: Colors.blueGrey),
|
|
labelText: 'Email',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
ElevatedButton(
|
|
onPressed: isLoading
|
|
? null
|
|
: () {
|
|
final email = emailController.text.trim();
|
|
if (email.isNotEmpty) {
|
|
sendPasswordResetEmail(email);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Masukkan email terlebih dahulu'),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF81D4FA),
|
|
minimumSize: const Size(double.infinity, 48),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child: isLoading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Text(
|
|
'Kirim Link Reset',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
letterSpacing: 1.1,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text(
|
|
'Kembali ke Login',
|
|
style: TextStyle(color: Colors.blueGrey),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|