From 072becb3f086c4b4b197ff0c42d430bc817195fa Mon Sep 17 00:00:00 2001 From: Vincent Paulin Date: Thu, 22 Aug 2024 20:16:24 +0200 Subject: [PATCH] feat: format in onChanged --- lib/pages/add_bridge/login_form.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pages/add_bridge/login_form.dart b/lib/pages/add_bridge/login_form.dart index eda0df4c40..32cad49b5e 100644 --- a/lib/pages/add_bridge/login_form.dart +++ b/lib/pages/add_bridge/login_form.dart @@ -107,11 +107,21 @@ class WhatsAppLoginForm extends StatelessWidget { Text(L10n.of(context)!.enterYourDetails), const SizedBox(height: 5), IntlPhoneField( + disableLengthCheck: true, initialCountryCode: Localizations.localeOf(context).languageCode.toUpperCase(), onChanged: (PhoneNumber phoneNumberField) { - controller.text = phoneNumberField.completeNumber; + String localNumber = phoneNumberField.number; + + // If the local number begins with '0', it is removed + if (localNumber.startsWith('0')) { + localNumber = localNumber.substring(1); + } + + // Reconstruct the complete number with the country code + controller.text = '${phoneNumberField.countryCode}$localNumber'; }, + // Initial country code via language used in Locale currentLocale languageCode: Localizations.localeOf(context).languageCode, onCountryChanged: (country) {},