-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not having a complete phone number with country code #37
Comments
Facing the same issue. |
Any solution for this |
I'm having this issue. I cannot access .fullNumber either to get around it. |
If the user enters the number first and then selects the country then the country code is included. But, if they select the country first then enter the number the country code is not returned . |
I have the same issue since updating to the latest version and updating to Dart 3. Here's my code:
This previously worked fine but now the country code is not being added to the value. For example, using phone number +447700900123, If you write the number (7700900123), then reselect the country (+44) it works. If you select the country (+44), then add the number (7700900123) it doesn't get included and login fails. Previously you could just write the number and leave the country as the preselected one with no issues. Versions being used: |
Any solution found ? Because I strugle with this bug also. |
Facing the same issue.... |
As is right now, this package is broken. In the end I have migrated to the intl_phone_field package. For those who want to integrate it with import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:intl_phone_field/countries.dart';
import 'package:intl_phone_field/helpers.dart';
import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:intl_phone_field/phone_number.dart';
class FormBuilderIntlPhoneField extends StatefulWidget {
final String name;
final InputDecoration? decoration;
final String? initialCountryCode;
final List<Country>? countries;
final String? invalidNumberMessage;
final bool isRequired;
// Expose here more fields from IntlPhoneField as needed
const FormBuilderIntlPhoneField({
super.key,
required this.name,
this.decoration,
this.initialCountryCode,
this.countries,
this.invalidNumberMessage,
this.isRequired = false,
});
@override
State<FormBuilderIntlPhoneField> createState() => _FormBuilderIntlPhoneFieldState();
}
class _FormBuilderIntlPhoneFieldState extends State<FormBuilderIntlPhoneField> {
String? _error;
final _fieldKey = GlobalKey<FormBuilderFieldState>();
_isValidIsRequired(PhoneNumber? phoneNumber) {
if (!widget.isRequired) {
return true;
}
return !(phoneNumber == null || phoneNumber.number.isEmpty || !isNumeric(phoneNumber.number));
}
@override
Widget build(BuildContext context) {
return FormBuilderField<PhoneNumber>(
key: _fieldKey,
name: widget.name,
validator: (phoneNumber) {
if (!_isValidIsRequired(phoneNumber)) {
return 'required'; // This message is not displayed at all in the UI
}
return null;
},
builder: (FormFieldState field) {
return IntlPhoneField(
decoration: InputDecoration(
labelText: widget.decoration?.labelText ?? 'Phone number',
suffixIcon: widget.decoration?.suffixIcon ?? const Icon(Icons.phone),
border: widget.decoration?.border ?? const UnderlineInputBorder(),
errorText: _error,
),
initialCountryCode: widget.initialCountryCode ?? 'US',
countries: widget.countries,
onChanged: (phoneNumber) => field.didChange(phoneNumber),
onSaved: (phoneNumber) {
field.didChange(phoneNumber);
if (!_isValidIsRequired(phoneNumber)) {
setState(() => _error = FormBuilderLocalizations.of(context).requiredErrorText);
} else {
setState(() => _error = null);
}
},
invalidNumberMessage: widget.invalidNumberMessage,
validator: (phoneNumber) {
if (!_isValidIsRequired(phoneNumber)) {
setState(() => _error = FormBuilderLocalizations.of(context).requiredErrorText);
} else {
setState(() => _error = null);
}
return null;
},
);
},
);
}
} Then you can use it in your form like: ...
FormBuilderIntlPhoneField(
name: 'mobileNumber',
initialCountryCode: 'ES',
invalidNumberMessage: 'Número inválido',
isRequired: true,
decoration: InputDecoration(
labelText: 'Teléfono',
suffixIcon: const Icon(Icons.phone),
border: const OutlineInputBorder(),
),
),
... |
Is there an existing issue for this?
Package/Plugin version
2.0.1
Flutter doctor
Flutter doctor
Minimal code example
Code sample
Current Behavior
flutter: {phone_number: 743234567, phone_number_cupertino: 743234567}
The phone numbers are not complete with the country codes either after selecting or the initial country selected
Expected Behavior
The phone numbers inputed should have a country code
flutter: {phone_number: +254743234567, phone_number_cupertino: +254743234567,}
Steps To Reproduce
Using the example here and run it
Aditional information
The text was updated successfully, but these errors were encountered: