Asset-Borrowing-App / lib / Project / LoginPage / verify_email.dart
verify_email.dart
Raw
// import 'dart:async';
// import 'package:firebase_auth/firebase_auth.dart';
// import 'package:flutter/material.dart';
// import 'package:flutter_application_1/Project/NavigationBar.dart';

// class VerifyEmailPage extends StatefulWidget {
//   const VerifyEmailPage({Key? key}) : super(key: key);

//   @override
//   _VerifyEmailPageState createState() => _VerifyEmailPageState();
// }

// class _VerifyEmailPageState extends State<VerifyEmailPage> {
//   bool isEmailVerified = false;
//   bool canResendEmail = false;
//   Timer? timer;

//   void showSnackBar(BuildContext context, String message) {
//   SnackBar snackBar = SnackBar(content: Text(message));
//   ScaffoldMessenger.of(context).showSnackBar(snackBar);
// }

//   @override
//   void initState() {
//     super.initState();

//     // Send email verification on page load
//     isEmailVerified = FirebaseAuth.instance.currentUser!.emailVerified;

//     if (!isEmailVerified) {
//       FirebaseAuth.instance.currentUser!.sendEmailVerification();

//       timer = Timer.periodic(const Duration(seconds: 3), (_) => checkEmailVerified());
//     }
//   }

//   @override
//   void dispose() {
//     timer?.cancel();
//     super.dispose();
//   }

//   Future<void> checkEmailVerified() async {
//     await FirebaseAuth.instance.currentUser!.reload();

//     setState(() {
//       isEmailVerified = FirebaseAuth.instance.currentUser!.emailVerified;
//     });

//     if (isEmailVerified) timer?.cancel();
//   }

//   Future<void> sendEmailVerification() async {
//     try {
//       final user = FirebaseAuth.instance.currentUser!;
//       await user.sendEmailVerification();

//       setState(() => canResendEmail = false);
//       await Future.delayed(const Duration(seconds: 5));
//       setState(() => canResendEmail = true);
//     } catch (e) {
//       showSnackBar(context, e.toString());
//     }
// }

//   @override
//   Widget build(BuildContext context) => isEmailVerified
//       ? MyBottomNavigationBar()
//       : Scaffold(
//           appBar: AppBar(
//             title: const Text('Verify Email'),
//           ),
//           body: Padding(
//             padding: const EdgeInsets.all(16.0),
//             child: Column(
//               mainAxisAlignment: MainAxisAlignment.center,
//               children: [
//                 Text(
//                   'A verification email has been sent to your email address.',
//                   style: const TextStyle(fontSize: 20.0),
//                   textAlign: TextAlign.center,
//                 ),
//                 const SizedBox(height: 24.0),
//                 ElevatedButton.icon(
//                   style: ElevatedButton.styleFrom(
//                     minimumSize: const Size.fromHeight(50.0),
//                   ),
//                   icon: const Icon(Icons.email, size: 32.0),
//                   label: const Text(
//                     'Resend Email',
//                     style: TextStyle(fontSize: 24.0),
//                   ),
//                   onPressed: canResendEmail ? sendEmailVerification : null,
//                 ),
//                 const SizedBox(height: 8),
//                 TextButton(
//                   style: ElevatedButton.styleFrom(
//                     minimumSize: const Size.fromHeight(50),
//                   ),
//                   child: const Text(
//                     'Cancel',
//                     style: TextStyle(fontSize: 24.0),
//                   ),
//                   onPressed: () => FirebaseAuth.instance.signOut(),
//                 )
//               ],
//             ),
//           ),
//         );
// }
// //   final FirebaseAuth _auth = FirebaseAuth.instance;

// //   @override
// //   void initState() {
// //     super.initState();

// //     // Send email verification on page load
// //     _auth.currentUser?.sendEmailVerification();
// //   }

// //   @override
// //   Widget build(BuildContext context) {
// //     return Scaffold(
// //       appBar: AppBar(
// //         title: const Text('Verify Email'),
// //       ),
// //       body: Padding(
// //         padding: const EdgeInsets.all(16.0),
// //         child: Column(
// //           mainAxisAlignment: MainAxisAlignment.center,
// //           children: <Widget>[
// //             const Text(
// //               'A verification email has been sent to your email address.',
// //               textAlign: TextAlign.center,
// //               style: TextStyle(fontSize: 18.0),
// //             ),
// //             const SizedBox(height: 16.0),
// //             const Text(
// //               'Please click on the verification link in the email to complete the verification process.',
// //               textAlign: TextAlign.center,
// //               style: TextStyle(fontSize: 18.0),
// //             ),
// //             const SizedBox(height: 16.0),
// //             ElevatedButton(
// //               onPressed: () async {
// //                 // Sign out the current user
// //                 await _auth.signOut();

// //                 // Navigate to the sign in page
// //                 Navigator.pushNamedAndRemoveUntil(
// //                     context, '/sign-in', (route) => false);
// //               },
// //               child: const Text('Sign Out'),
// //             ),
// //           ],
// //         ),
// //       ),
// //     );
// //   }
// // }