搜索插件、代码仓与 APP 分类

插件详情v1.0.4

international_phone_input

适用于 Flutter 的国际电话号码输入。此包使用 libphonenumber 包验证电话号码输入值。

近 30 天下载
84
喜欢数
43
Pub 分数
40

安装插件

flutter pub add international_phone_input

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于处理国际电话号码输入的 Flutter 包,使用 libphonenumber 库进行内置验证。它提供了一个用户友好的界面,可根据国家特定标准输入和格式化电话号码,确保在全球用户中准确收集数据。该包可自动根据输入或选定的默认值检测国家,应用正确的格式,并实时验证输入的号码。

适合场景

  • 全球用户注册
  • 国际联系表单
  • 电话号码验证工作流程
  • 多区域移动应用
  • 电子商务结账流程

主要特点

  • 实时手机号验证
  • 自动国家代码检测
  • 带掩码的格式化输入
  • 支持所有主要国家
  • 与 libphonenumber 的集成

适合对象

  • 面向国际受众的应用程序
  • 需要有效电话号码的表单
  • 需要强大输入验证的开发人员
  • 使用国际化功能的项目
  • 具有合规性需求的应用程序

使用建议

  • 需要互联网以进行完整的国家数据库查询
  • 由于 libphonenumber 依赖项,可能会增加应用大小
  • UI 组件的自定义功能有限
  • 不支持离线验证
  • 依赖外部库更新

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

international_phone_input

International Phone Number Input For Flutter

Usage

Just put the component in your application.

import 'package:international_phone_input/international_phone_input.dart';

String phoneNumber;
String phoneIsoCode;

void onPhoneNumberChange(String number, String internationalizedPhoneNumber, String isoCode) {
    setState(() {
       phoneNumber = number;
       phoneIsoCode = isoCode;
    });
}

// Default Widget with dropdown list
@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child: InternationalPhoneInput(
          onPhoneNumberChange: onPhoneNumberChange, 
          initialPhoneNumber: phoneNumber,
          initialSelection: phoneIsoCode,
          enabledCountries: ['+233', '+1']
       ),
     ),
 );

// Widget with text input only

 onValidPhoneNumber(
      String number, String internationalizedPhoneNumber, String isoCode) {
    setState(() {
      confirmedNumber = internationalizedPhoneNumber;
    });
  }

@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child:  InternationalPhoneInputText(
         onValidPhoneNumber: onValidPhoneNumber,
        ),
     ),
 );

// Widget with decoration
// Using decoration overwrites other styles such as hintStyle, hintText, etc.

@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child: InternationalPhoneInput(
          decoration: InputDecoration.collapsed(hintText: '(416) 123-4567'),
          onPhoneNumberChange: onPhoneNumberChange, 
          initialPhoneNumber: phoneNumber,
          initialSelection: phoneIsoCode,
          enabledCountries: ['+233', '+1'],
          showCountryCodes: false
       ),
     ),
 );

Customization

Here is a list of properties available to customize the widget:

Name Type Description
initialPhoneNumber String used to set initial phone number
initialSelection String used to set initial country code
errorText String use this to set an error message
hintText String sets hint
labelText String sets label
errorStyle TextStyle style applied to error message
hintStyle TextStyle style applied to hint
labelStyle TextStyle style applied to label
errorMaxLines int the maximum number of lines user can type
enabledCountries List the list of enabled countries to display
decoration InputDecoration decoration applied to the TextField widget
showCountryCodes bool shows the country code (default true)
showCountryFlags bool shows. the country flags (default true)
dropdownIcon Widget use this to customize dropdown icon

Contributions

Contributions of any kind are more than welcome! Feel free to fork and improve international_phone_input in any way you want, make a pull request, or open an issue.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目