Flutter - 国际 Phone 字段 - 检查 Phone 相关国家/地区数量的最大长度
Flutter - International Phone Field - Check Max Length of Phone Number of Related Country
我在我的 flutter 应用程序中添加了 intl_phone_field。它工作得很好。我用的是2.0.1版本
我是这样写的;
IntlPhoneField(
decoration: InputDecoration(
labelText: "Phone Number",
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
initialCountryCode: 'US', //default country code
onChanged: (phone) {
//when phone number country code is changed
print(phone.completeNumber); //get complete number
print(phone.countryCode); // get country code only
print(phone.number); // only phone number
},),
好像是下面这张图。正如他们的开发者在变更日志中提到的那样,他们添加了几个国家/地区的最大长度 phone 个数字。因此,正如我在下面的图片上用红色箭头显示的那样,有一个长度字段。
phone 号码长度取决于每个国家/地区。所以我的问题是,例如对于这张图片,我如何检查输入的 10/10 数字字符?
访问此值有点棘手,但您可以:
除了 intl_phone_field.dart
:
之外,首先导入此文件
import 'package:intl_phone_field/countries.dart';
然后:
IntlPhoneField(
...
onChanged: (phone) {
print(countries.firstWhere((element) => element['code'] == phone.countryISOCode)['max_length']);
},
),
我在我的 flutter 应用程序中添加了 intl_phone_field。它工作得很好。我用的是2.0.1版本
我是这样写的;
IntlPhoneField(
decoration: InputDecoration(
labelText: "Phone Number",
labelStyle: TextStyle(
fontSize: 14.0,
),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 10.0,
),
),
initialCountryCode: 'US', //default country code
onChanged: (phone) {
//when phone number country code is changed
print(phone.completeNumber); //get complete number
print(phone.countryCode); // get country code only
print(phone.number); // only phone number
},),
好像是下面这张图。正如他们的开发者在变更日志中提到的那样,他们添加了几个国家/地区的最大长度 phone 个数字。因此,正如我在下面的图片上用红色箭头显示的那样,有一个长度字段。
phone 号码长度取决于每个国家/地区。所以我的问题是,例如对于这张图片,我如何检查输入的 10/10 数字字符?
访问此值有点棘手,但您可以:
除了 intl_phone_field.dart
:
import 'package:intl_phone_field/countries.dart';
然后:
IntlPhoneField(
...
onChanged: (phone) {
print(countries.firstWhere((element) => element['code'] == phone.countryISOCode)['max_length']);
},
),