如何在 flutter 的登录页面中添加国家代码保管箱?
How do I add a country code dropbox in a login page in flutter?
我正在尝试在登录页面中使用手机号码添加国家代码下拉框,但它显示了一些或其他错误。我需要一种简单的方法来添加带有 [=12= 的国家代码下拉框] 人数
将此添加到 pubsec.yaml
中的依赖项
country_code_picker: ^2.0.2
然后导入这个库
导入'package:country_code_picker/country_code_picker.dart';
将此代码添加到您的主文件
Container(
child: CountryCodePicker(
initialSelection: 'IN',
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
favorite: ['+91' , 'IN'],
enabled: true,
hideMainText: false,
showFlagMain: true,
showFlag: true,
hideSearch: false,
showFlagDialog: true,
alignLeft: true,
)
),
Container(
padding: const EdgeInsets.all(8),
child: TextField(
maxLength: 10,
controller: nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Mobile Number',
),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
]
),
),
将此添加到依赖项中的 pubspec.yaml:
intl_phone_field: ^3.0.1
导入以下包:
import 'package:intl_phone_field/intl_phone_field.dart';
添加此代码:
IntlPhoneField(
decoration: InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
initialCountryCode: 'IN',
onChanged: (phone) {
print(phone.completeNumber);
},
)
我正在尝试在登录页面中使用手机号码添加国家代码下拉框,但它显示了一些或其他错误。我需要一种简单的方法来添加带有 [=12= 的国家代码下拉框] 人数
将此添加到 pubsec.yaml
中的依赖项country_code_picker: ^2.0.2
然后导入这个库
导入'package:country_code_picker/country_code_picker.dart';
将此代码添加到您的主文件
Container(
child: CountryCodePicker(
initialSelection: 'IN',
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
favorite: ['+91' , 'IN'],
enabled: true,
hideMainText: false,
showFlagMain: true,
showFlag: true,
hideSearch: false,
showFlagDialog: true,
alignLeft: true,
)
),
Container(
padding: const EdgeInsets.all(8),
child: TextField(
maxLength: 10,
controller: nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Mobile Number',
),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
]
),
),
将此添加到依赖项中的 pubspec.yaml:
intl_phone_field: ^3.0.1
导入以下包:
import 'package:intl_phone_field/intl_phone_field.dart';
添加此代码:
IntlPhoneField(
decoration: InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
initialCountryCode: 'IN',
onChanged: (phone) {
print(phone.completeNumber);
},
)