Flutter城市(省市區)選擇器

nerdMoss發表於2019-09-19

Flutter城市(省市區)選擇器

address_picker

pub: pub.flutter-io.cn/packages/ad…

github: github.com/SiriDx/addr…

image

新增依賴

dependencies:
    address_picker: ^0.0.1
複製程式碼

簡單使用

import 'package:address_picker/address_picker.dart';
複製程式碼
class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: FlatButton(
          child: Text('show'),
          onPressed: () {
            showModalBottomSheet(
                context: context,
                builder: (context) => BottomSheet(
                    onClosing: () {},
                    builder: (context) => Container(
                          height: 250.0,
                          child: AddressPicker(
                            style: TextStyle(color: Colors.black, fontSize: 17),
                            mode: AddressPickerMode.provinceCityAndDistrict,
                            onSelectedAddressChanged: (address) {
                              print('${address.currentProvince.province}');
                              print('${address.currentCity.city}');
                              print('${address.currentDistrict.area}');
                            },
                          ),
                        )));
          },
        ),
      ),
    );
  }
}
複製程式碼

屬性

  • mode:
/// 選擇模式
/// province 一級: 省
/// provinceAndCity 二級: 省市 
/// provinceCityAndDistrict 三級: 省市區
final AddressPickerMode mode;
複製程式碼
  • onSelectedAddressChanged:
/// 選中的地址發生改變回撥
final AddressCallback onSelectedAddressChanged;
複製程式碼
  • style:
/// 省市區文字顯示樣式
final TextStyle style;
複製程式碼

相關文章