25-12-1/1
This commit is contained in:
@@ -310,6 +310,61 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
final _phoneController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
static String formatSyrianPhone(String phone) {
|
||||
// Remove spaces, symbols, +, -, ()
|
||||
phone = phone.replaceAll(RegExp(r'[ \-\(\)\+]'), '').trim();
|
||||
|
||||
// Normalize 00963 → 963
|
||||
if (phone.startsWith('00963')) {
|
||||
phone = phone.replaceFirst('00963', '963');
|
||||
}
|
||||
|
||||
// Normalize 0963 → 963
|
||||
if (phone.startsWith('0963')) {
|
||||
phone = phone.replaceFirst('0963', '963');
|
||||
}
|
||||
|
||||
// NEW: Fix 96309xxxx → 9639xxxx
|
||||
if (phone.startsWith('96309')) {
|
||||
phone = '9639' + phone.substring(5); // remove the "0" after 963
|
||||
}
|
||||
|
||||
// If starts with 9630 → correct to 9639
|
||||
if (phone.startsWith('9630')) {
|
||||
phone = '9639' + phone.substring(4);
|
||||
}
|
||||
|
||||
// If already in correct format: 9639xxxxxxxx
|
||||
if (phone.startsWith('9639') && phone.length == 12) {
|
||||
return phone;
|
||||
}
|
||||
|
||||
// If starts with 963 but missing the 9
|
||||
if (phone.startsWith('963') && phone.length > 3) {
|
||||
// Ensure it begins with 9639
|
||||
if (!phone.startsWith('9639')) {
|
||||
phone = '9639' + phone.substring(3);
|
||||
}
|
||||
return phone;
|
||||
}
|
||||
|
||||
// If starts with 09xxxxxxxx → 9639xxxxxxxx
|
||||
if (phone.startsWith('09')) {
|
||||
return '963' + phone.substring(1);
|
||||
}
|
||||
|
||||
// If 9xxxxxxxx (9 digits)
|
||||
if (phone.startsWith('9') && phone.length == 9) {
|
||||
return '963' + phone;
|
||||
}
|
||||
|
||||
// If starts with incorrect 0xxxxxxx → assume Syrian and fix
|
||||
if (phone.startsWith('0') && phone.length == 10) {
|
||||
return '963' + phone.substring(1);
|
||||
}
|
||||
|
||||
return phone;
|
||||
}
|
||||
|
||||
void _submit() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
@@ -318,7 +373,10 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
final rawPhone = _phoneController.text.trim().replaceFirst('+', '');
|
||||
final success = await PhoneAuthHelper.sendOtp(rawPhone);
|
||||
if (success && mounted) {
|
||||
Get.to(() => OtpVerificationScreen(phoneNumber: rawPhone));
|
||||
// Get.to(() => OtpVerificationScreen(phoneNumber: rawPhone));
|
||||
await PhoneAuthHelper.verifyOtp(
|
||||
rawPhone,
|
||||
); // For testing purposes, auto-verify with a dummy OTP
|
||||
}
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
@@ -349,6 +407,7 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
dropdownTextStyle: const TextStyle(color: Colors.black87),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Phone Number'.tr,
|
||||
hintText: 'witout zero'.tr,
|
||||
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -365,11 +424,14 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
},
|
||||
validator: (phone) {
|
||||
if (phone == null || phone.number.isEmpty) {
|
||||
return 'Please enter your phone number';
|
||||
return 'Please enter your phone number'.tr;
|
||||
}
|
||||
if (phone.number.startsWith('0')) {
|
||||
return 'Please enter the number without the leading 0'.tr;
|
||||
}
|
||||
if (phone.completeNumber.length < 10) {
|
||||
// Example validation
|
||||
return 'Phone number seems too short';
|
||||
return 'Phone number seems too short'.tr;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -419,7 +481,7 @@ class _OtpVerificationScreenState extends State<OtpVerificationScreen> {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
setState(() => _isLoading = true);
|
||||
// PRODUCTION READY: Using the actual PhoneAuthHelper
|
||||
await PhoneAuthHelper.verifyOtp(widget.phoneNumber, _otpController.text);
|
||||
// await PhoneAuthHelper.verifyOtp(widget.phoneNumber, _otpController.text);
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user