MIF_E31222389/lib/auth/verification.dart

126 lines
4.5 KiB
Dart

import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:permainan_kata_anak_sd/utils/audio_manager.dart';
import 'package:permainan_kata_anak_sd/auth/auth.dart';
import 'package:permainan_kata_anak_sd/utils/wrapper.dart';
class VerificationPage extends StatefulWidget {
final User user;
const VerificationPage({required this.user, super.key});
@override
State<VerificationPage> createState() => _VerificationPageState();
}
class _VerificationPageState extends State<VerificationPage> {
final _auth = AuthService();
late Timer timer;
@override
void initState() {
super.initState();
_auth.sendEmailVerificationLink();
timer = Timer.periodic(Duration(seconds: 5), (timer) {
FirebaseAuth.instance.currentUser?.reload();
if (FirebaseAuth.instance.currentUser!.emailVerified == true) {
timer.cancel();
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const Wrapper(),
));
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background_loginregister.png'),
fit: BoxFit.cover, // Menutupi seluruh layar
),
),
padding: const EdgeInsets.all(40),
child: Stack(
children: [
// Konten Utama
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 220, // Atur lebar container
height: 150, // Atur tinggi container
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/icons/popup.png'),
fit: BoxFit.contain,
),
),
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 25), // Sesuaikan padding untuk mengatur posisi teks
child: Center(
// Menambahkan Center widget
child: Text(
"We have sent an email for verifivcation, if you haven't received an email, please tap the button",
textAlign: TextAlign.center,
style: const TextStyle(
color: Color.fromARGB(255, 65, 44, 23),
fontSize: 9,
fontFamily:
'Bestime' // Mengecilkan ukuran font agar lebih sesuai
),
),
),
),
const SizedBox(height: 20),
Container(
width: 300,
height: 70,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/icons/button.png'),
fit: BoxFit.contain,
),
),
child: ElevatedButton(
onPressed: () async {
AudioManager.playClickSound();
_auth.sendEmailVerificationLink();
},
style: ButtonStyle(
minimumSize:
MaterialStateProperty.all(const Size(0, 0)),
backgroundColor:
MaterialStateProperty.all(Colors.transparent),
elevation: MaterialStateProperty.all(0),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
)),
overlayColor:
MaterialStateProperty.all(Colors.transparent),
),
child: const Text(
'Resend Email',
style: TextStyle(
color: Color.fromARGB(225, 103, 75, 47),
fontSize: 12,
fontFamily: 'Bestime',
),
),
),
),
],
),
),
],
),
),
);
}
}