Files
kent_logistics_app/lib/screens/otp_screen.dart

140 lines
4.3 KiB
Dart
Raw Normal View History

2025-11-28 10:14:30 +05:30
import 'package:flutter/material.dart';
import '../widgets/rounded_input.dart';
import '../widgets/primary_button.dart';
import '../services/request_service.dart';
import 'waiting_screen.dart';
class OtpScreen extends StatefulWidget {
final Map<String, dynamic> signupPayload;
const OtpScreen({super.key, required this.signupPayload});
@override
State<OtpScreen> createState() => _OtpScreenState();
}
class _OtpScreenState extends State<OtpScreen> {
final otpController = TextEditingController();
bool verifying = false;
2025-12-11 18:36:11 +05:30
static const String defaultOtp = '123456';
2025-11-28 10:14:30 +05:30
void _verifyAndSubmit() async {
final entered = otpController.text.trim();
2025-12-11 18:36:11 +05:30
2025-11-28 10:14:30 +05:30
if (entered.length != 6) {
2025-12-11 18:36:11 +05:30
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Enter 6 digit OTP')));
2025-11-28 10:14:30 +05:30
return;
}
if (entered != defaultOtp) {
2025-12-11 18:36:11 +05:30
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Invalid OTP')));
2025-11-28 10:14:30 +05:30
return;
}
setState(() => verifying = true);
2025-12-03 11:57:05 +05:30
final res = await RequestService(context).sendSignup(widget.signupPayload);
2025-11-28 10:14:30 +05:30
setState(() => verifying = false);
if (res['status'] == true || res['status'] == 'success') {
2025-12-11 18:36:11 +05:30
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const WaitingScreen()));
2025-11-28 10:14:30 +05:30
} else {
final message = res['message']?.toString() ?? 'Failed';
2025-12-11 18:36:11 +05:30
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message)));
2025-11-28 10:14:30 +05:30
}
}
@override
Widget build(BuildContext context) {
2025-12-11 18:36:11 +05:30
final width = MediaQuery.of(context).size.width;
/// 📌 Universal scale factor for responsiveness
final scale = (width / 390).clamp(0.85, 1.25);
2025-11-28 10:14:30 +05:30
return Scaffold(
2025-12-11 18:36:11 +05:30
body: SafeArea(
child: Stack(
children: [
/// 🔙 Back Button
Positioned(
top: 18 * scale,
left: 18 * scale,
child: GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
height: 42 * scale,
width: 42 * scale,
decoration: const BoxDecoration(
color: Colors.indigo,
shape: BoxShape.circle,
),
child: Icon(Icons.arrow_back,
color: Colors.white, size: 22 * scale),
),
),
),
/// 🟦 Center Card
Center(
child: Container(
width: width * 0.90,
padding: EdgeInsets.symmetric(
horizontal: 20 * scale, vertical: 28 * scale),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16 * scale),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 12 * scale,
offset: Offset(0, 4 * scale),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"OTP Verification",
style: TextStyle(
fontSize: 22 * scale,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 10 * scale),
Text(
"Enter the 6-digit OTP sent to your mobile/email.\n(Default OTP: 123456)",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13.5 * scale),
),
SizedBox(height: 18 * scale),
RoundedInput(
controller: otpController,
hint: "Enter OTP",
keyboardType: TextInputType.number,
),
SizedBox(height: 22 * scale),
PrimaryButton(
label: "Verify & Submit",
onTap: _verifyAndSubmit,
busy: verifying,
),
],
),
),
),
],
),
2025-11-28 10:14:30 +05:30
),
);
}
}