Files
blinds_flutter/lib/BlindMasterScreens/email_verification_waiting_screen.dart

208 lines
6.2 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:blind_master/BlindMasterResources/error_snackbar.dart';
import 'package:flutter/material.dart';
import 'package:blind_master/BlindMasterResources/title_text.dart';
2026-01-08 17:50:51 -06:00
abstract class BaseVerificationWaitingScreen extends StatefulWidget {
const BaseVerificationWaitingScreen({super.key});
}
2026-01-08 17:50:51 -06:00
abstract class BaseVerificationWaitingScreenState<T extends BaseVerificationWaitingScreen> extends State<T> {
Timer? _pollingTimer;
bool _isChecking = false;
2026-01-08 17:50:51 -06:00
// Abstract methods to be implemented by subclasses
String get title;
String get mainMessage;
String? get highlightedInfo => null;
String get instructionMessage;
String get successMessage;
Future<bool> checkStatus();
Future<void> resendVerification();
void onSuccess();
@override
void initState() {
super.initState();
_startPolling();
}
@override
void dispose() {
_pollingTimer?.cancel();
super.dispose();
}
void _startPolling() {
_pollingTimer = Timer.periodic(Duration(seconds: 5), (timer) {
2026-01-08 17:50:51 -06:00
_checkStatus();
});
}
2026-01-08 17:50:51 -06:00
Future<void> _checkStatus() async {
if (_isChecking) return;
setState(() {
_isChecking = true;
});
try {
2026-01-08 17:50:51 -06:00
final isComplete = await checkStatus();
2026-01-08 17:50:51 -06:00
if (isComplete) {
_pollingTimer?.cancel();
if (!mounted) return;
onSuccess();
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.green[800],
duration: Duration(seconds: 4),
content: Text(
successMessage,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15),
),
)
);
}
} catch (e) {
// Silently fail for polling - don't show error to user
2026-01-08 17:50:51 -06:00
print('Status check failed: $e');
} finally {
if (mounted) {
setState(() {
_isChecking = false;
});
}
}
}
2026-01-08 17:50:51 -06:00
Future<void> _handleResend() async {
try {
2026-01-08 17:50:51 -06:00
await resendVerification();
if (!mounted) return;
2026-01-08 17:50:51 -06:00
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.green[800],
content: Text(
"Verification email sent! Please check your inbox.",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15),
),
)
);
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
errorSnackbar(e)
);
}
}
Future<void> _onRefresh() async {
2026-01-08 17:50:51 -06:00
await _checkStatus();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
onRefresh: _onRefresh,
child: Container(
color: Theme.of(context).primaryColorLight,
child: ListView(
physics: AlwaysScrollableScrollPhysics(),
children: [
Container(
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2026-01-08 17:50:51 -06:00
TitleText(title, txtClr: Colors.white),
SizedBox(height: 30),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Text(
2026-01-08 17:50:51 -06:00
mainMessage,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
),
2026-01-08 17:50:51 -06:00
if (highlightedInfo != null) ...[
SizedBox(height: 10),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Text(
highlightedInfo!,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
],
SizedBox(height: 20),
if (_isChecking)
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
)
else
Icon(
Icons.email_outlined,
size: 80,
color: Colors.white70,
),
SizedBox(height: 30),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Text(
2026-01-08 17:50:51 -06:00
instructionMessage,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
fontSize: 14,
),
),
),
SizedBox(height: 40),
ElevatedButton(
2026-01-08 17:50:51 -06:00
onPressed: _handleResend,
child: Text("Resend Verification Email"),
),
SizedBox(height: 20),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Text(
"Pull down to check verification status manually",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white54,
fontSize: 12,
fontStyle: FontStyle.italic,
),
),
),
],
),
),
],
),
),
),
);
}
}