Initial Flutter project added
This commit is contained in:
67
lib/screens/otp_screen.dart
Normal file
67
lib/screens/otp_screen.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
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;
|
||||
|
||||
static const String defaultOtp = '123456'; // default OTP as you said
|
||||
|
||||
void _verifyAndSubmit() async {
|
||||
final entered = otpController.text.trim();
|
||||
if (entered.length != 6) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter 6 digit OTP')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (entered != defaultOtp) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Invalid OTP')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => verifying = true);
|
||||
|
||||
// send signup payload to backend
|
||||
final res = await RequestService().sendSignup(widget.signupPayload);
|
||||
|
||||
setState(() => verifying = false);
|
||||
|
||||
if (res['status'] == true || res['status'] == 'success') {
|
||||
// navigate to waiting screen
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const WaitingScreen()));
|
||||
} else {
|
||||
final message = res['message']?.toString() ?? 'Failed';
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pad = MediaQuery.of(context).size.width * 0.06;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("OTP Verification")),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: pad, vertical: 20),
|
||||
child: Column(children: [
|
||||
const Text("Enter the 6-digit OTP sent to your mobile/email. (Default OTP: 123456)"),
|
||||
const SizedBox(height: 20),
|
||||
RoundedInput(controller: otpController, hint: "Enter OTP", keyboardType: TextInputType.number),
|
||||
const SizedBox(height: 14),
|
||||
PrimaryButton(label: "Verify & Submit", onTap: _verifyAndSubmit, busy: verifying),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user