TPIN Set Screen OTP Implemented

This commit is contained in:
2025-09-11 16:18:37 +05:30
parent 191610c9b2
commit 0f205873a9
3 changed files with 241 additions and 147 deletions

View File

@@ -1,10 +1,48 @@
import '../../../l10n/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:kmobile/features/fund_transfer/screens/tpin_otp_screen.dart';
import 'package:kmobile/api/services/change_password_service.dart'; // <-- Add this import
import 'package:kmobile/di/injection.dart'; // <-- Add this import
class TpinSetupPromptScreen extends StatelessWidget {
class TpinSetupPromptScreen extends StatefulWidget {
const TpinSetupPromptScreen({super.key});
@override
State<TpinSetupPromptScreen> createState() => _TpinSetupPromptScreenState();
}
class _TpinSetupPromptScreenState extends State<TpinSetupPromptScreen> {
// 3. Add state variables
bool _isLoading = false;
final ChangePasswordService _changePasswordService = getIt<ChangePasswordService>();
Future<void> _getOtp() async {
setState(() {
_isLoading = true;
});
try {
await _changePasswordService.getOtp(mobileNumber: '8981274001');
if (mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const TpinOtpScreen()),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: ${e.toString()}')),
);
}
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@@ -37,30 +75,33 @@ class TpinSetupPromptScreen extends StatelessWidget {
),
),
const SizedBox(height: 32),
ElevatedButton.icon(
icon: const Icon(Icons.arrow_forward_rounded),
label: Text(
AppLocalizations.of(context).setTpin,
style:
const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
style: ElevatedButton.styleFrom(
backgroundColor: theme.colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(
vertical: 14,
horizontal: 32,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const TpinOtpScreen()),
);
},
),
ElevatedButton.icon(
icon: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: const Icon(Icons.arrow_forward_rounded),
label: Text(
AppLocalizations.of(context).setTpin,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
style: ElevatedButton.styleFrom(
backgroundColor: theme.colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(
vertical: 14,
horizontal: 32,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
onPressed: _isLoading ? null : _getOtp, // <-- Use the new function
),
const SizedBox(height: 18),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0),
@@ -77,4 +118,4 @@ class TpinSetupPromptScreen extends StatelessWidget {
),
);
}
}
}