2026-06-10 13:29:04 +05:30
|
|
|
import 'dart:async';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import '../theme.dart';
|
2026-06-10 13:48:06 +05:30
|
|
|
import '../route_transitions.dart';
|
2026-06-10 17:43:21 +05:30
|
|
|
import '../feedback_helper.dart';
|
2026-06-10 13:29:04 +05:30
|
|
|
import 'business_setup_screen.dart';
|
|
|
|
|
|
|
|
|
|
class OtpVerificationScreen extends StatefulWidget {
|
|
|
|
|
final String mobileNumber;
|
|
|
|
|
|
|
|
|
|
const OtpVerificationScreen({super.key, required this.mobileNumber});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<OtpVerificationScreen> createState() => _OtpVerificationScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OtpVerificationScreenState extends State<OtpVerificationScreen> {
|
|
|
|
|
late Timer _timer;
|
|
|
|
|
int _timeLeft = 45;
|
|
|
|
|
final List<TextEditingController> _controllers = List.generate(6, (_) => TextEditingController());
|
|
|
|
|
final List<FocusNode> _focusNodes = List.generate(6, (_) => FocusNode());
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_startCountdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _startCountdown() {
|
|
|
|
|
_timeLeft = 45;
|
|
|
|
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
|
|
|
|
if (_timeLeft <= 0) {
|
|
|
|
|
_timer.cancel();
|
|
|
|
|
} else {
|
|
|
|
|
setState(() {
|
|
|
|
|
_timeLeft--;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_timer.cancel();
|
|
|
|
|
for (var controller in _controllers) {
|
|
|
|
|
controller.dispose();
|
|
|
|
|
}
|
|
|
|
|
for (var node in _focusNodes) {
|
|
|
|
|
node.dispose();
|
|
|
|
|
}
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 17:43:21 +05:30
|
|
|
void _verifyOtp() {
|
|
|
|
|
final code = _controllers.map((c) => c.text.trim()).join();
|
|
|
|
|
if (code.length < 6) {
|
|
|
|
|
AppFeedback.error();
|
|
|
|
|
showTopAlert(context, 'Please enter a valid 6-digit OTP code.', isError: true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AppFeedback.success();
|
|
|
|
|
showTopAlert(context, 'OTP Verified Successfully!');
|
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
|
context,
|
|
|
|
|
FadeSlidePageRoute(child: const BusinessSetupScreen()),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 13:29:04 +05:30
|
|
|
String _getFormattedTime() {
|
|
|
|
|
return '00:${_timeLeft.toString().padLeft(2, '0')}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final padding = context.responsivePadding;
|
|
|
|
|
|
|
|
|
|
final displayMobile = widget.mobileNumber.length == 10
|
|
|
|
|
? '+91 ${widget.mobileNumber.substring(0, 5)} ${widget.mobileNumber.substring(5)}'
|
|
|
|
|
: '+91 ${widget.mobileNumber}';
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Color(0xFFBA1A20)),
|
2026-06-10 17:43:21 +05:30
|
|
|
onPressed: () {
|
|
|
|
|
AppFeedback.click();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
'PozoApp',
|
|
|
|
|
style: theme.textTheme.headlineMedium?.copyWith(
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: padding),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'Step 2.5 of 5',
|
|
|
|
|
style: theme.textTheme.labelMedium?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
bottom: PreferredSize(
|
|
|
|
|
preferredSize: const Size.fromHeight(6),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: List.generate(5, (index) {
|
|
|
|
|
return Expanded(
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 6,
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 2.0),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: index <= 1
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: (index == 2 ? theme.colorScheme.primary.withOpacity(0.5) : theme.colorScheme.surfaceContainerHighest),
|
|
|
|
|
borderRadius: BorderRadius.circular(3),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: ConstrainedBox(
|
|
|
|
|
constraints: const BoxConstraints(maxWidth: 600),
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
2026-06-10 14:47:50 +05:30
|
|
|
// Alert envelope pulse symbol with SlideFadeEntrance
|
|
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: Duration.zero,
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 96,
|
|
|
|
|
height: 96,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.surfaceContainerHigh,
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 72,
|
|
|
|
|
height: 72,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black.withOpacity(0.06),
|
|
|
|
|
blurRadius: 10,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.sms,
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
size: 38,
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
2026-06-10 14:47:50 +05:30
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 100),
|
|
|
|
|
child: Text(
|
|
|
|
|
'Verifying your number',
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
style: theme.textTheme.headlineMedium?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
2026-06-10 14:47:50 +05:30
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 150),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"Sent code to $displayMobile",
|
|
|
|
|
style: theme.textTheme.bodyMedium,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
InteractiveScale(
|
2026-06-10 17:43:21 +05:30
|
|
|
onTap: () {
|
|
|
|
|
AppFeedback.click();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
2026-06-10 14:47:50 +05:30
|
|
|
child: Text(
|
|
|
|
|
'Edit',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
],
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
const SizedBox(height: 20),
|
2026-06-10 13:29:04 +05:30
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
// 6 Custom Inputs Fields with SlideFadeEntrance
|
|
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 200),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: List.generate(11, (index) {
|
|
|
|
|
if (index.isOdd) {
|
|
|
|
|
return const SizedBox(width: 8);
|
|
|
|
|
}
|
|
|
|
|
final fieldIndex = index ~/ 2;
|
|
|
|
|
return SizedBox(
|
|
|
|
|
width: 44,
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _controllers[fieldIndex],
|
|
|
|
|
focusNode: _focusNodes[fieldIndex],
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
maxLength: 1,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
decoration: InputDecoration(
|
|
|
|
|
counterText: '',
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
borderSide: BorderSide(color: theme.colorScheme.outlineVariant),
|
|
|
|
|
),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
borderSide: BorderSide(color: theme.colorScheme.primary, width: 2),
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
onChanged: (value) {
|
2026-06-10 17:43:21 +05:30
|
|
|
AppFeedback.subtleHaptic();
|
|
|
|
|
if (value.isNotEmpty) {
|
|
|
|
|
if (fieldIndex < 5) {
|
|
|
|
|
_focusNodes[fieldIndex + 1].requestFocus();
|
|
|
|
|
} else {
|
|
|
|
|
_verifyOtp();
|
|
|
|
|
}
|
|
|
|
|
} else if (value.isEmpty && fieldIndex > 0) {
|
|
|
|
|
_focusNodes[fieldIndex - 1].requestFocus();
|
2026-06-10 14:47:50 +05:30
|
|
|
}
|
|
|
|
|
},
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
const SizedBox(height: 24),
|
2026-06-10 13:29:04 +05:30
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
// Auto detect loader card with SlideFadeEntrance
|
|
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 250),
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.surfaceContainerLow,
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 14,
|
|
|
|
|
height: 14,
|
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
valueColor: AlwaysStoppedAnimation(theme.colorScheme.primary),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Text(
|
|
|
|
|
'Auto-detecting OTP...',
|
|
|
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
|
|
|
|
|
// Resending timer action row
|
|
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 300),
|
2026-06-10 13:29:04 +05:30
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
2026-06-10 14:47:50 +05:30
|
|
|
const Icon(Icons.schedule, size: 16, color: Colors.grey),
|
|
|
|
|
const SizedBox(width: 6),
|
2026-06-10 13:29:04 +05:30
|
|
|
Text(
|
2026-06-10 14:47:50 +05:30
|
|
|
_timeLeft > 0
|
|
|
|
|
? 'Resend code in ${_getFormattedTime()}'
|
|
|
|
|
: 'Resend Code via SMS',
|
|
|
|
|
style: theme.textTheme.bodyMedium,
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
// WhatsApp custom CTA button with InteractiveScale
|
|
|
|
|
SlideFadeEntrance(
|
|
|
|
|
delay: const Duration(milliseconds: 350),
|
|
|
|
|
child: InteractiveScale(
|
|
|
|
|
child: OutlinedButton.icon(
|
|
|
|
|
onPressed: () {
|
2026-06-10 17:43:21 +05:30
|
|
|
AppFeedback.click();
|
2026-06-10 14:47:50 +05:30
|
|
|
showTopAlert(
|
|
|
|
|
context,
|
|
|
|
|
'WhatsApp verification request sent!',
|
|
|
|
|
icon: Icons.chat_bubble_outline,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.forum, color: Colors.green, size: 18),
|
|
|
|
|
label: const Text(
|
2026-06-10 13:29:04 +05:30
|
|
|
'Resend via WhatsApp',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2026-06-10 14:47:50 +05:30
|
|
|
color: Colors.black87,
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
),
|
2026-06-10 14:47:50 +05:30
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
side: const BorderSide(color: Color(0xFFE2E2E2)),
|
|
|
|
|
elevation: 1,
|
|
|
|
|
minimumSize: const Size(220, 48),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// Pinned Bottom Dock
|
|
|
|
|
Container(
|
|
|
|
|
height: 80,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
border: Border(top: BorderSide(color: Colors.grey[200]!)),
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: ConstrainedBox(
|
|
|
|
|
constraints: const BoxConstraints(maxWidth: 600),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
|
children: [
|
2026-06-10 14:47:50 +05:30
|
|
|
_buildFooterAction(Icons.help_outline, 'Help', () {
|
|
|
|
|
showTopAlert(
|
|
|
|
|
context,
|
|
|
|
|
'Support agent contacted. We will call you shortly.',
|
|
|
|
|
icon: Icons.support_agent_outlined,
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
_buildFooterAction(Icons.save, 'Save Draft', () {
|
|
|
|
|
showTopAlert(
|
|
|
|
|
context,
|
|
|
|
|
'Onboarding draft saved successfully!',
|
|
|
|
|
icon: Icons.save_outlined,
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
InteractiveScale(
|
|
|
|
|
child: TextButton.icon(
|
2026-06-10 17:43:21 +05:30
|
|
|
onPressed: _verifyOtp,
|
2026-06-10 14:47:50 +05:30
|
|
|
icon: const Text(
|
|
|
|
|
'Verify Manually',
|
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
label: const Icon(Icons.arrow_forward, size: 16),
|
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
backgroundColor: theme.colorScheme.primary,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
2026-06-10 13:29:04 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 14:47:50 +05:30
|
|
|
Widget _buildFooterAction(IconData icon, String label, VoidCallback onTap) {
|
|
|
|
|
return InteractiveScale(
|
2026-06-10 17:43:21 +05:30
|
|
|
onTap: () {
|
|
|
|
|
AppFeedback.click();
|
|
|
|
|
onTap();
|
|
|
|
|
},
|
2026-06-10 14:47:50 +05:30
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(icon, color: Colors.grey[600], size: 22),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Text(
|
|
|
|
|
label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.grey[600],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-06-10 13:29:04 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|