csc_picker
a flutter package to display a country, states, and cities. in addition it gives the possibility to select a list of countries, states and cities depends on selected, also you can search country, state, and city all around the world.
how to use
to use this package, add csc_picker
as a dependency in your pubspec.yaml.
cscpicker(
oncountrychanged: (value) {
setstate(() {
countryvalue = value;
});
},
onstatechanged:(value) {
setstate(() {
statevalue = value;
});
},
oncitychanged:(value) {
setstate(() {
cityvalue = value;
});
},
),
you will get feedback in onchanged functions
parameters
parameterstypedescription
flagstate | countryflag | enable (get flag with country name) / disable (disable flag) / showindropdownonly (display flag in dropdown only) |
layout | layout | toggle dropdown layout (horizontal / vertical) |
showstates | boolean | enable disable states dropdown (true / false) |
showcities | boolean | enable disable cities dropdown (true / false) |
dropdowndecoration | boxdecoration | dropdown box decoration to style your dropdown selector [optional parameter] (use with disableddropdowndecoration) |
disableddropdowndecoration | boxdecoration | disabled dropdown box decoration to style your dropdown selector [optional parameter] (use with disabled dropdowndecoration) |
selecteditemstyle | textstyle | to change selected item style |
dropdownheadingstyle | textstyle | to change dropdowndialog heading style |
dropdownitemstyle | textstyle | to change dropdowndialog item style |
dropdowndialogradius | double | to change dropdowndialogbox radius |
searchbarradius | double | to change search bar radius |
defaultcountry | defaultcountry | to select default country |
disablecountry | disablecountry | disable country dropdown (note: use it with default country) |
countrysearchplaceholder | string | placeholder for country search field |
statesearchplaceholder | string | placeholder for state search field |
citysearchplaceholder | string | placeholder for city search field |
countrydropdownlabel | string | label/title for country dropdown |
countrydropdownlabel | string | label/title for state dropdown |
countrydropdownlabel | string | label/title for city dropdown |
example
import 'package:csc_picker/csc_picker.dart';
import 'package:flutter/material.dart';
/// this is a implementation of the country state city picker.
void main() {
runapp(myapp());
}
class myapp extends statelesswidget {
@override
widget build(buildcontext context) {
return materialapp(
title: 'csc picker',
theme: themedata(
primaryswatch: colors.blue,
visualdensity: visualdensity.adaptiveplatformdensity,
),
home: myhomepage(title: 'csc picker'),
);
}
}
class myhomepage extends statefulwidget {
myhomepage({key key, this.title}) : super(key: key);
final string title;
@override
_myhomepagestate createstate() => _myhomepagestate();
}
class _myhomepagestate extends state<myhomepage> {
/// variables to store country state city data in onchanged method.
string countryvalue = "";
string statevalue = "";
string cityvalue = "";
string address = "";
@override
widget build(buildcontext context) {
globalkey<cscpickerstate> _cscpickerkey = globalkey();
return scaffold(
appbar: appbar(
title: text(widget.title),
),
body: center(
child: container(
padding: edgeinsets.symmetric(horizontal: 20),
height: 600,
child: column(
children: [
///adding csc picker widget in app
cscpicker(
///enable disable state dropdown [optional parameter]
showstates: true,
/// enable disable city drop down [optional parameter]
showcities: true,
///enable (get flag with country name) / disable (disable flag) / showindropdownonly (display flag in dropdown only) [optional parameter]
flagstate: countryflag.disable,
///dropdown box decoration to style your dropdown selector [optional parameter] (use with disableddropdowndecoration)
dropdowndecoration: boxdecoration(
borderradius: borderradius.all(radius.circular(10)),
color: colors.white,
border:
border.all(color: colors.grey.shade300, width: 1)),
///disabled dropdown box decoration to style your dropdown selector [optional parameter] (use with disabled dropdowndecoration)
disableddropdowndecoration: boxdecoration(
borderradius: borderradius.all(radius.circular(10)),
color: colors.grey.shade300,
border:
border.all(color: colors.grey.shade300, width: 1)),
///placeholders for dropdown search field
countrysearchplaceholder: "country",
statesearchplaceholder: "state",
citysearchplaceholder: "city",
///labels for dropdown
countrydropdownlabel: "*country",
statedropdownlabel: "*state",
citydropdownlabel: "*city",
///default country
//defaultcountry: defaultcountry.india,
///disable country dropdown (note: use it with default country)
//disablecountry: true,
///selected item style [optional parameter]
selecteditemstyle: textstyle(
color: colors.black,
fontsize: 14,
),
///dropdowndialog heading style [optional parameter]
dropdownheadingstyle: textstyle(
color: colors.black,
fontsize: 17,
fontweight: fontweight.bold),
///dropdowndialog item style [optional parameter]
dropdownitemstyle: textstyle(
color: colors.black,
fontsize: 14,
),
///dialog box radius [optional parameter]
dropdowndialogradius: 10.0,
///search bar radius [optional parameter]
searchbarradius: 10.0,
///triggers once country selected in dropdown
oncountrychanged: (value) {
setstate(() {
///store value in country variable
countryvalue = value;
});
},
///triggers once state selected in dropdown
onstatechanged: (value) {
setstate(() {
///store value in state variable
statevalue = value;
});
},
///triggers once city selected in dropdown
oncitychanged: (value) {
setstate(() {
///store value in city variable
cityvalue = value;
});
},
),
///print newly selected country state and city in text widget
textbutton(
onpressed: () {
setstate(() {
address = "$cityvalue, $statevalue, $countryvalue";
});
},
child: text("print data")),
text(address)
],
)),
),
);
}
}
Comments are closed.