feature/medora-55 (#8)
Files has been renamed and small changes made Co-authored-by: Jipson George <152465898+Jipson-cosq@users.noreply.github.com> Reviewed-on: cosqnet/telemednet#8 Co-authored-by: DhanshCOSQ <dhanshas@cosq.net> Co-committed-by: DhanshCOSQ <dhanshas@cosq.net>
This commit is contained in:
parent
b1ae31c7dd
commit
42543367a4
@ -97,11 +97,11 @@ class DoctorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addQualification(String qualification) {
|
void addQualification(String qualification) {
|
||||||
model.qualifications!.add(qualification);
|
model.qualifications!.add(qualification.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeQualification(String qualification) {
|
void removeQualification(String qualification) {
|
||||||
model.qualifications!.remove(qualification);
|
model.qualifications!.remove(qualification.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateFloorBuilding(String floorBuilding) {
|
void updateFloorBuilding(String floorBuilding) {
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl_phone_field/intl_phone_field.dart';
|
import 'package:intl_phone_field/intl_phone_field.dart';
|
||||||
import 'package:medora/data/services/data_service.dart';
|
import 'package:medora/data/services/data_service.dart';
|
||||||
@ -26,123 +24,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
|
|
||||||
// Add focus nodes to handle keyboard navigation
|
|
||||||
final _emailFocusNode = FocusNode();
|
|
||||||
final _passwordFocusNode = FocusNode();
|
|
||||||
|
|
||||||
// Email validation patterns
|
|
||||||
final RegExp _emailRegex = RegExp(
|
|
||||||
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
|
|
||||||
caseSensitive: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Common email domain validation
|
|
||||||
final List<String> _commonEmailDomains = [
|
|
||||||
'gmail.com',
|
|
||||||
'yahoo.com',
|
|
||||||
'hotmail.com',
|
|
||||||
'outlook.com'
|
|
||||||
];
|
|
||||||
|
|
||||||
String? _validateEmail(String? value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return 'Email address is required';
|
|
||||||
}
|
|
||||||
|
|
||||||
value = value.trim();
|
|
||||||
|
|
||||||
// Basic format validation
|
|
||||||
if (!_emailRegex.hasMatch(value)) {
|
|
||||||
return 'Please enter a valid email address';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check email length
|
|
||||||
if (value.length > 254) {
|
|
||||||
return 'Email address is too long';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split email into local and domain parts
|
|
||||||
final parts = value.split('@');
|
|
||||||
if (parts.length != 2) {
|
|
||||||
return 'Invalid email format';
|
|
||||||
}
|
|
||||||
|
|
||||||
final localPart = parts[0];
|
|
||||||
final domainPart = parts[1].toLowerCase();
|
|
||||||
|
|
||||||
// Validate local part
|
|
||||||
if (localPart.isEmpty || localPart.length > 64) {
|
|
||||||
return 'Invalid email username';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for common typos in popular domains
|
|
||||||
for (final domain in _commonEmailDomains) {
|
|
||||||
if (domainPart.length > 3 &&
|
|
||||||
domainPart != domain &&
|
|
||||||
_calculateLevenshteinDistance(domainPart, domain) <= 2) {
|
|
||||||
return 'Did you mean @$domain?';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Additional domain validation
|
|
||||||
if (!domainPart.contains('.')) {
|
|
||||||
return 'Invalid email domain';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String? _validatePassword(String? value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return 'Password is required';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.length < 6) {
|
|
||||||
return 'Password must be at least 6 characters';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value.contains(RegExp(r'[A-Z]'))) {
|
|
||||||
return 'Password must contain at least one uppercase letter';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value.contains(RegExp(r'[0-9]'))) {
|
|
||||||
return 'Password must contain at least one number';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value.contains(RegExp(r'[!@#$%^&*(),.?":{}|<>]'))) {
|
|
||||||
return 'Password must contain at least one special character';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate Levenshtein distance for typo detection
|
|
||||||
int _calculateLevenshteinDistance(String a, String b) {
|
|
||||||
if (a.isEmpty) return b.length;
|
|
||||||
if (b.isEmpty) return a.length;
|
|
||||||
|
|
||||||
List<int> previousRow = List<int>.generate(b.length + 1, (i) => i);
|
|
||||||
List<int> currentRow = List<int>.filled(b.length + 1, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < a.length; i++) {
|
|
||||||
currentRow[0] = i + 1;
|
|
||||||
|
|
||||||
for (int j = 0; j < b.length; j++) {
|
|
||||||
int insertCost = previousRow[j + 1] + 1;
|
|
||||||
int deleteCost = currentRow[j] + 1;
|
|
||||||
int replaceCost = previousRow[j] + (a[i] != b[j] ? 1 : 0);
|
|
||||||
|
|
||||||
currentRow[j + 1] = [insertCost, deleteCost, replaceCost].reduce(min);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<int> temp = previousRow;
|
|
||||||
previousRow = currentRow;
|
|
||||||
currentRow = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return previousRow[b.length];
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -170,7 +51,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
focusNode: _emailFocusNode,
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Email',
|
labelText: 'Email',
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
@ -185,25 +65,22 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
),
|
),
|
||||||
prefixIcon: const Icon(Icons.email_outlined,
|
prefixIcon: const Icon(Icons.email_outlined,
|
||||||
color: Colors.blue),
|
color: Colors.blue),
|
||||||
errorMaxLines: 2,
|
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.emailAddress,
|
keyboardType: TextInputType.emailAddress,
|
||||||
textInputAction: TextInputAction.next,
|
validator: (value) {
|
||||||
onFieldSubmitted: (_) {
|
if (value?.isEmpty ?? true) {
|
||||||
_passwordFocusNode.requestFocus();
|
return 'Please enter your email';
|
||||||
},
|
|
||||||
validator: _validateEmail,
|
|
||||||
onChanged: (value) {
|
|
||||||
// Trigger validation on change if the field was previously invalid
|
|
||||||
if (_formKey.currentState?.validate() ?? false) {
|
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$')
|
||||||
|
.hasMatch(value!)) {
|
||||||
|
return 'Please enter a valid email';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
focusNode: _passwordFocusNode,
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Password',
|
labelText: 'Password',
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
@ -229,15 +106,16 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
onPressed: () => setState(
|
onPressed: () => setState(
|
||||||
() => _obscurePassword = !_obscurePassword),
|
() => _obscurePassword = !_obscurePassword),
|
||||||
),
|
),
|
||||||
errorMaxLines: 2,
|
|
||||||
),
|
),
|
||||||
obscureText: _obscurePassword,
|
obscureText: _obscurePassword,
|
||||||
validator: _validatePassword,
|
validator: (value) {
|
||||||
onChanged: (value) {
|
if (value?.isEmpty ?? true) {
|
||||||
// Trigger validation on change if the field was previously invalid
|
return 'Please enter your password';
|
||||||
if (_formKey.currentState?.validate() ?? false) {
|
|
||||||
setState(() {});
|
|
||||||
}
|
}
|
||||||
|
if ((value?.length ?? 0) < 6) {
|
||||||
|
return 'Password must be at least 6 characters';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
@ -262,7 +140,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
},
|
},
|
||||||
validator: (phone) {
|
validator: (phone) {
|
||||||
if (phone?.completeNumber.isEmpty ?? true) {
|
if (phone?.completeNumber.isEmpty ?? true) {
|
||||||
return 'Phone number is required';
|
return 'Please enter your phone number';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
@ -287,7 +165,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
|
|
||||||
Future<void> _handleSignUp() async {
|
Future<void> _handleSignUp() async {
|
||||||
if (_formKey.currentState == null || !_formKey.currentState!.validate()) {
|
if (_formKey.currentState == null || !_formKey.currentState!.validate()) {
|
||||||
_showErrorSnackBar('Please fix the errors in the form');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,8 +222,6 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_emailController.dispose();
|
_emailController.dispose();
|
||||||
_passwordController.dispose();
|
_passwordController.dispose();
|
||||||
_emailFocusNode.dispose();
|
|
||||||
_passwordFocusNode.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,11 +88,11 @@ class _DoctorServicesMenuScreen extends State<DoctorServicesMenuScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// const Icon(
|
const Icon(
|
||||||
// Icons.chevron_right,
|
Icons.chevron_right,
|
||||||
// color: Colors.white,
|
color: Colors.white,
|
||||||
// size: 30,
|
size: 30,
|
||||||
// ),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -60,19 +60,39 @@ class _DoctorAddressScreenState extends State<DoctorAddressScreen> {
|
|||||||
_addressTypeController =
|
_addressTypeController =
|
||||||
TextEditingController(text: doctor.addressType ?? '');
|
TextEditingController(text: doctor.addressType ?? '');
|
||||||
selectedAddressType = widget.controller?.model.addressType;
|
selectedAddressType = widget.controller?.model.addressType;
|
||||||
if (widget.controller?.model.addressType != null) {
|
if (selectedAddressType != null &&
|
||||||
final existingType = widget.controller!.model.addressType!;
|
!addressTypes.contains(selectedAddressType)) {
|
||||||
selectedAddressType = existingType;
|
showCustomTypeField = true;
|
||||||
|
|
||||||
// If it's a custom type (not in predefined list)
|
|
||||||
if (!addressTypes.contains(existingType)) {
|
|
||||||
showCustomTypeField = true;
|
|
||||||
_addressTypeController.text = existingType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bool _validateAndProceed() {if (_formKey.currentState!.validate()) {
|
||||||
|
// // Update the address model
|
||||||
|
// _controller.updateFloorBuilding(_floorBuildingController.text);
|
||||||
|
// _controller.updateStreet(_streetController.text);
|
||||||
|
// _controller.updateCity(_cityController.text);
|
||||||
|
// _controller.updateState(_stateController.text);
|
||||||
|
// _controller.updateCountry(_countryController.text);
|
||||||
|
// _controller.updatePostalCode(_postalCodeController.text);
|
||||||
|
|
||||||
|
// // Validate the address fields
|
||||||
|
// if (_areFieldsValid()) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
// const SnackBar(content: Text('Please fill in all required fields')),
|
||||||
|
// );
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
bool _validateAndProceed() {
|
bool _validateAndProceed() {
|
||||||
|
// if (!_formKey.currentState!.validate()) return false;
|
||||||
|
// if (selectedAddressType == null) {
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||||
|
// content: Text('Please select an address type'),
|
||||||
|
// backgroundColor: Colors.red,
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
_controller.updateFloorBuilding(_floorBuildingController.text);
|
_controller.updateFloorBuilding(_floorBuildingController.text);
|
||||||
_controller.updateStreet(_streetController.text);
|
_controller.updateStreet(_streetController.text);
|
||||||
@ -97,6 +117,20 @@ class _DoctorAddressScreenState extends State<DoctorAddressScreen> {
|
|||||||
_addressTypeController.text.isNotEmpty;
|
_addressTypeController.text.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bool _validateAndProceed() {
|
||||||
|
// if (!_formKey.currentState!.validate()) return false;
|
||||||
|
// if (selectedAddressType == null) {
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
// const SnackBar(
|
||||||
|
// content: Text('Please select an address type'),
|
||||||
|
// backgroundColor: Colors.red,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
void _handleAddressTypeSelection(String type) {
|
void _handleAddressTypeSelection(String type) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (type == 'Others') {
|
if (type == 'Others') {
|
||||||
@ -104,15 +138,11 @@ class _DoctorAddressScreenState extends State<DoctorAddressScreen> {
|
|||||||
if (!showCustomTypeField) {
|
if (!showCustomTypeField) {
|
||||||
_addressTypeController.clear();
|
_addressTypeController.clear();
|
||||||
selectedAddressType = null;
|
selectedAddressType = null;
|
||||||
widget.controller?.updateAddressType('');
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showCustomTypeField = false;
|
showCustomTypeField = false;
|
||||||
_addressTypeController
|
|
||||||
.clear(); // Clear the custom field if it was active
|
|
||||||
selectedAddressType = type;
|
selectedAddressType = type;
|
||||||
widget.controller
|
widget.controller?.updateAddressType(type);
|
||||||
?.updateAddressType(type); // Update controller with selected type
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -404,7 +434,7 @@ class _DoctorAddressScreenState extends State<DoctorAddressScreen> {
|
|||||||
if (isMandatory && (value == null || value.isEmpty)) {
|
if (isMandatory && (value == null || value.isEmpty)) {
|
||||||
return '$label is required';
|
return '$label is required';
|
||||||
}
|
}
|
||||||
if (value != null && !RegExp(r'^(?!0{6})\d{6}$').hasMatch(value)) {
|
if (value != null && !RegExp(r'^[0-9]+$').hasMatch(value)) {
|
||||||
return 'Please enter numbers only';
|
return 'Please enter numbers only';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -242,6 +242,7 @@ class _ProfileUploadPageState extends State<ProfileUploadPage> {
|
|||||||
children: [
|
children: [
|
||||||
_buildUniformField(
|
_buildUniformField(
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
|
|
||||||
icon: Icons.person,
|
icon: Icons.person,
|
||||||
child:
|
child:
|
||||||
Container(), // The child parameter is not used in this implementation
|
Container(), // The child parameter is not used in this implementation
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user