国家选择器
一个 Flutter 包,用于从国家列表中选择一个国家。

入门
将包添加到您的 pubspec.yaml
country_picker: ^1.0.4
在您的 dart 文件中,导入库
import 'package:country_picker/country_picker.dart';
使用 showCountryPicker 显示国家选择器
showCountryPicker(
context: context,
showPhoneCode: true, // optional. Shows phone code before the country name.
onSelect: (Country country) {
print('Select country: ${country.displayName}');
},
);
参数
onSelect:当选择国家时调用。国家选择器将新值传递给回调函数(必需)showPhoneCode:可用于在国家名称前显示电话区号。exclude:可用于从国家列表中排除(删除)一个或多个国家(可选)。
showCountryPicker(
context: context,
exclude: <String>['KN', 'MF'], //It takes a list of country code(iso2).
onSelect: (Country country) => print('Select country: ${country.displayName}'),
);