국제화 지원 기능을 내장한 전화번호 입력 필드를 제공하는 플러터 패키지입니다. 사용자의 로케일에 따라 전화번호를 자동으로 형식화하고 검증하여 다양한 국가에서 올바른 입력 패턴을 보장합니다. 플러터의 로컬라이제이션 시스템과 통합되어 언어 및 지역 설정에 따라 동적으로 적응합니다. 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 여러 플랫폼을 지원하며, 정확한 전화번호 처리가 필요한 글로벌 애플리케이션에 이상적입니다.
사용 사례
전화번호 입력이 필요한 국제 앱
양식의 다국어 지원
자동 전화번호 형식 지정
크로스플랫폼 모바일 및 웹 앱
사용자 친화적인 연락처 정보 수집
동적 국가 코드 감지
주요 기능
내장된 국제화
실시간 전화번호 검증
국가별 자동 형식 지정
모든 주요 플랫폼을 지원합니다
Flutter i18n과의 원활한 통합
사용자 정의 가능한 입력 동작
적합한 대상
글로벌 애플리케이션
양식 중심 앱
다양한 지역을 대상으로 하는 앱
Flutter 로컬라이제이션을 사용하는 개발자
일관된 전화 입력 UX가 필요한 팀
고려 사항
적절한 로컬라이제이션 설정이 필요합니다
UI 일관성을 위해 사용자 정의 스타일이 필요할 수 있습니다
외부 국가 데이터에 의존함
처음에는 지원되는 지역 설정에만 제한됨
대규모 데이터셋과 함께 가능한 성능 영향
다양한 지역에서 테스트가 필요합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
phone_form_field
Flutter phone input integrated with flutter internationalization
Features
Totally cross platform, this is a dart only package / dependencies
Internationalization: many languages supported
Semantics
Phone formatting localized by region
Phone number validation (built-in validators included for main use cases)
Support auto fill and copy paste
Uses dart phone_numbers_parser for parsing
Form field
Demo
Demo available at https://cedvdb.github.io/phone_form_field/
Usage
PhoneFormField();
/// paramsPhoneFormField(
initialValue: PhoneNumber.parse('+33'), // or use the controller
validator: PhoneValidator.compose(
[PhoneValidator.required(), PhoneValidator.validMobile()]),
countrySelectorNavigator: constCountrySelectorNavigator.page(),
onChanged: (phoneNumber) => print('changed into $phoneNumber'),
enabled: true,
isCountrySelectionEnabled: true,
isCountryButtonPersistent: true,
countryButtonStyle: constCountryButtonStyle(
showDialCode: true,
showIsoCode: true,
showFlag: true,
flagSize: 16
),
// + all parameters of TextField// + all parameters of FormField// ...
);
Validation
Built-in validators
required : PhoneValidator.required
valid : PhoneValidator.valid (default value when no validator supplied)
valid mobile number : PhoneValidator.validMobile
valid fixed line number : PhoneValidator.validFixedLine
valid type : PhoneValidator.validType
valid country : PhoneValidator.validCountry
none : PhoneValidator.none (this can be used to disable default valid validator)
Validators details
Each validator has an optional errorText property to override built-in translated text
Composing validators
Validator can be a composed set of validators built-in or custom validator using PhoneValidator.compose, see example below.
Note that when composing validators, the sorting is important as the error message displayed is the first validator failing.
PhoneFormField(
// ...
validator: PhoneValidator.compose([
// list of validators to usePhoneValidator.required(errorText: "You must enter a value"),
PhoneValidator.validMobile(),
// ..
]),
)
Country selector
Here are the list of the parameters available for all built-in country selector :
Name
Default value
Description
countries
null
Countries available in list view (all countries are listed when omitted)
favorites
null
List of country code ['FR','UK'] to display on top of the list
addSeparator
true
Whether to add a separator between favorite countries and others one. Useless if favorites parameter is null
showCountryCode
true
Whether to display the country dial code as listTile item subtitle
sortCountries
false
Whether the countries should appear in alphabetic order, if false the countries are displayed in the same order as countries property (Note that favorite countries are listed in supplied order whatever the value of this parameter)
noResultMessage
null
The message to be displayed in place of the list when search result is empty (a default localised message is used when omitted)
Built-in country selector
CountrySelectorNavigator.page
Open a page to select the country.
No extra parameters
CountrySelectorNavigator.dialog
Open a dialog to select the country.
No extra parameters
CountrySelectorNavigator.bottomSheet
Open a bottom sheet expanding to all available space in both axis
No extra parameters
CountrySelectorNavigator.modalBottomSheet
Open a modal bottom sheet expanded horizontally
Extra parameters:
height (double, default null)
Allow to determine the height of the bottom sheet, will expand to all available height when omitted
CountrySelectorNavigator.draggableBottomSheet
Open a modal bottom sheet expanded horizontally which may be dragged from a minimum to a maximum of current available height.
Uses internally the DraggableScrollableSheet flutter widget
Extra parameters:
initialChildSize (double, default: 0.5) factor of current available height used when opening
minChildSize (double, default: 0.Z5) : maximum factor of current available height
minChildSize (double, default: 0.Z5) : minimum factor of current available height
borderRadius (BorderRadiusGeometry, default: 16px circular radius on top left/right)
Custom Country Selector Navigator
You can use your own country selector by creating a class that implements CountrySelectorNavigator
It has one required method show expected to return the selected country:
classCustomCountrySelectorNavigatorimplementsCountrySelectorNavigator{
Future<Country?> show(BuildContext context) {
// ask user for a country and return related `Country` class
}
}
// usagePhoneFormField(
// ...
selectorNavigator: CustomCountrySelectorNavigator(),
// ...
)
Internationalization
Dynamic localization
This package uses the flutter_country_selector package under the hood, which exports a method for dynamic localization CountrySelectorLocalization.of(context).countryName(isoCode).
If one of the language you target is not supported you can submit a pull request in flutter_country_selector and phone_form_field repositories.
Overwriting or adding custom flags
Some users have expressed their need to change some flags due to political reasons, or stylistic reasons. You might also wish to add your own flags. To do so refer to this issue: https://github.com/cedvdb/phone_form_field/issues/222