Starlight Country Picker
starlight_country_picker 是一个国家选择器。
功能
☑️ 添加新国家
☑️ 搜索你的国家
⭐ 我们的包未使用 setState ❤️
安装
将 starlight_country_picker 添加为 pubspec 文件的依赖项。
starlight_country_picker:
git:
url: https://github.com/YeMyoAung/starlight_country_picker.git
用法
首先,您需要导入我们的包。
import 'package:starlight_country_picker/country_picker.dart';
国家选择器
Starlight Country Picker 的使用与其他对话框函数一样。
import 'package:flutter/material.dart';
import 'package:starlight_country_picker/country_picker.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () async {
final Country? _country = await countryPicker(
context,///required
selectedColor: Colors.green,///optional
unSelectedColor: Colors.black,///optional
supportedCountry: [],///optional
addNewSupportedCountry: [],///optional
width: 100,///optional
height: 100,///optional
backgroundColor: Colors.white,///optional
hintStyle: TextStyle(),///optional
barrierDismissible: true,///optional
barrierColor: Colors.black54,///optional
);
print(_country.toString());
},
child: const Text(
"Country Picker",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
);
}
}
国家模型
const Country country = Country(dialCode: '+95',name: 'Myanmar',flag: '??');