Compare commits

...
3 Commits
Author SHA1 Message Date
risadmin_prod 012969ae21 updating user grp to 41 in otp page 2026-09-19 03:14:30 +00:00
risadmin_prod cc4d9491c9 updating ussergrp is to 41 2026-09-19 03:13:50 +00:00
risadmin_prod 334efa1de5 adding validation and toast for login issue 2026-09-18 18:23:17 +00:00
2 changed files with 96 additions and 67 deletions
@@ -4,7 +4,6 @@ import 'package:flutter/services.dart';
import '../../Utils/image_constant.dart'; import '../../Utils/image_constant.dart';
import '../../Utils/size_utils.dart'; import '../../Utils/size_utils.dart';
import '../../providers/token_manager.dart';
import '../../theme/app_style.dart'; import '../../theme/app_style.dart';
import '../../widgets/app_bar/appbar_image.dart'; import '../../widgets/app_bar/appbar_image.dart';
import '../../widgets/app_bar/appbar_title.dart'; import '../../widgets/app_bar/appbar_title.dart';
@@ -30,12 +29,18 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
final Map<String, dynamic> formData = {}; final Map<String, dynamic> formData = {};
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
late BuildContext _context; // Store the current context
var account_id = null; // Initialize with null var account_id = null; // Initialize with null
var selectedAccount; // Use nullable type var selectedAccount; // Use nullable type
var newPassword = ''; // Store the value of the confirm password field var newPassword = ''; // Store the value of the confirm password field
var confirmPassword = ''; // Store the value of the confirm password field var confirmPassword = ''; // Store the value of the confirm password field
bool _isSubmitting = false;
late final FocusNode _firstNameNode;
late final FocusNode _lastNameNode;
late final FocusNode _mobileNode;
late final FocusNode _newPasswordNode;
late final FocusNode _confirmPasswordNode;
// Validate that the passwords match // Validate that the passwords match
String? _validatePasswordMatch(String value) { String? _validatePasswordMatch(String value) {
if (value != newPassword) { if (value != newPassword) {
@@ -50,9 +55,12 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
bool _isPasswordValid = true; bool _isPasswordValid = true;
void _validatePassword(String password) { void _validatePassword(String password) {
setState(() { final valid = password.isNotEmpty;
_isPasswordValid = password.isNotEmpty; if (valid != _isPasswordValid) {
}); setState(() {
_isPasswordValid = valid;
});
}
} }
bool _isEmailValid = true; bool _isEmailValid = true;
@@ -86,12 +94,25 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_firstNameNode = FocusNode();
_lastNameNode = FocusNode();
_mobileNode = FocusNode();
_newPasswordNode = FocusNode();
_confirmPasswordNode = FocusNode();
}
@override
void dispose() {
_firstNameNode.dispose();
_lastNameNode.dispose();
_mobileNode.dispose();
_newPasswordNode.dispose();
_confirmPasswordNode.dispose();
super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_context = context; // Store the context
return Scaffold( return Scaffold(
appBar: CustomAppBar( appBar: CustomAppBar(
height: getVerticalSize(54), height: getVerticalSize(54),
@@ -112,9 +133,8 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Form( child: Form(
key: _formKey, key: _formKey,
child: Container( child: Column(
height: 500, mainAxisSize: MainAxisSize.min,
child: Column(
children: [ children: [
Padding( Padding(
padding: getPadding(top: 19), padding: getPadding(top: 19),
@@ -124,7 +144,7 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
style: style:
AppStyle.txtGilroyMedium16Bluegray900)), AppStyle.txtGilroyMedium16Bluegray900)),
CustomTextFormField( CustomTextFormField(
focusNode: FocusNode(), focusNode: _firstNameNode,
onsaved: (value) => formData['first_name'] = value, onsaved: (value) => formData['first_name'] = value,
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
@@ -145,7 +165,7 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
style: style:
AppStyle.txtGilroyMedium16Bluegray900)), AppStyle.txtGilroyMedium16Bluegray900)),
CustomTextFormField( CustomTextFormField(
focusNode: FocusNode(), focusNode: _lastNameNode,
onsaved: (value) => formData['last_name'] = value, onsaved: (value) => formData['last_name'] = value,
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
@@ -167,7 +187,7 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
style: style:
AppStyle.txtGilroyMedium16Bluegray900)), AppStyle.txtGilroyMedium16Bluegray900)),
CustomTextFormField( CustomTextFormField(
focusNode: FocusNode(), focusNode: _mobileNode,
textInputType: TextInputType.phone, textInputType: TextInputType.phone,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')) FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))
@@ -191,7 +211,7 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
style: style:
AppStyle.txtGilroyMedium16Bluegray900)), AppStyle.txtGilroyMedium16Bluegray900)),
CustomTextFormField( CustomTextFormField(
focusNode: FocusNode(), focusNode: _newPasswordNode,
hintText: "New Password", hintText: "New Password",
margin: getMargin(top: 6), margin: getMargin(top: 6),
padding: TextFormFieldPadding.PaddingT12, padding: TextFormFieldPadding.PaddingT12,
@@ -219,10 +239,8 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
), ),
onsaved: (value) => formData['new_password'] = value, onsaved: (value) => formData['new_password'] = value,
onChanged: (value) { onChanged: (value) {
setState(() { newPassword = value;
newPassword = value!; _validatePassword(value);
});
_validatePassword;
}, },
suffixConstraints: BoxConstraints( suffixConstraints: BoxConstraints(
maxHeight: getVerticalSize(44)), maxHeight: getVerticalSize(44)),
@@ -236,7 +254,7 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
style: style:
AppStyle.txtGilroyMedium16Bluegray900)), AppStyle.txtGilroyMedium16Bluegray900)),
CustomTextFormField( CustomTextFormField(
focusNode: FocusNode(), focusNode: _confirmPasswordNode,
hintText: "Confirm Password", hintText: "Confirm Password",
margin: getMargin(top: 6), margin: getMargin(top: 6),
padding: TextFormFieldPadding.PaddingT12, padding: TextFormFieldPadding.PaddingT12,
@@ -246,13 +264,11 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Please enter Password'; return 'Please enter Password';
} }
return _validatePasswordMatch(confirmPassword); return _validatePasswordMatch(value);
}, },
onsaved: (value) => formData['confirm_password'] = value, onsaved: (value) => formData['confirm_password'] = value,
onChanged: (value) { onChanged: (value) {
setState(() { confirmPassword = value; // Update confirmPassword
confirmPassword = value!; // Update confirmPassword
});
}, },
suffix: IconButton( suffix: IconButton(
icon: Icon( icon: Icon(
@@ -299,60 +315,73 @@ class _RegistrationDetailsScreenState extends State<RegistrationDetailsScreen> {
], ],
), ),
if (account_id != null) if (account_id == null)
Container( const Padding(
padding: EdgeInsets.only(top: 8),
child: Text(
'Tap + to create an account first, then SUBMIT will be enabled.',
style: TextStyle(fontSize: 12, color: Colors.grey),
),
),
Container(
margin: margin:
const EdgeInsets.symmetric(vertical: 5), // Add margin const EdgeInsets.symmetric(vertical: 5), // Add margin
child: CustomButton( child: CustomButton(
height: getVerticalSize(50), height: getVerticalSize(50),
width: getHorizontalSize(396), width: getHorizontalSize(396),
text: "SUBMIT", text: _isSubmitting ? "PLEASE WAIT..." : "SUBMIT",
margin: getMargin(top: 25), margin: getMargin(top: 25),
onTap: () async { onTap: (account_id == null || _isSubmitting)
if (_formKey.currentState!.validate()) { ? null
_formKey.currentState!.save(); : () async {
final isValid =
_formKey.currentState!.validate();
if (!isValid) {
showErrorMessage(
'Please fix the red errors (check passwords match).');
return;
}
_formKey.currentState!.save();
print('formdata is $formData'); print('formdata is $formData');
formData['usrGrpId'] = 46; formData['usrGrpId'] = 41;
formData['account_id'] = account_id; formData['account_id'] = account_id;
formData['email'] = widget.email; formData['email'] = widget.email;
{ setState(() => _isSubmitting = true);
try { try {
print(formData); print(formData);
await userService await userService.createuser(formData);
.createuser(formData)
.then((_) => {
const LoginScreen(),
});
await Future.delayed( if (!context.mounted) return;
const Duration(seconds: 5)); showSuccessMessage(
'User created successfully');
showSuccessMessage('User created successfully'); Navigator.pushAndRemoveUntil(
// ignore: use_build_context_synchronously context,
Navigator.push( MaterialPageRoute(
context, builder: (context) =>
MaterialPageRoute( const LoginScreen()),
builder: (context) => (route) => false);
const LoginScreen())); } catch (e) {
// moveToNextStep(); if (!context.mounted) return;
} catch (e) { showErrorMessage(
showErrorMessage('Failed to create User: $e'); 'Failed to create User: $e');
} } finally {
} if (mounted) {
} setState(() => _isSubmitting = false);
}, }
}
},
), ),
), ),
], ],
), ),
), ),
), ),
), ),
), );
); }
} }
}
@@ -146,7 +146,7 @@ class _SignUpUserScreenState extends State<SignUpUserScreenNew> {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
_formKey.currentState!.save(); _formKey.currentState!.save();
formData['usrGrpId'] = 46; formData['usrGrpId'] = 41;
formData['email'] = emailcontroller.text; formData['email'] = emailcontroller.text;
try { try {
print('send email data is $formData'); print('send email data is $formData');