Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State and cities drop down not working after selecting the country #84

Open
Prasiddha777 opened this issue Jan 15, 2024 · 3 comments
Open

Comments

@Prasiddha777
Copy link

Describe the bug
I followed your documentation and try to use it but i am unable to click on states and cities after i select on country. I followed the same example shown on pub my code looks like

/// Variables to store country state city data in onChanged method.
String countryValue = "";
String stateValue = "";
String cityValue = "";
String address = "";
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20),
height: 600,
child: Column(
children: [
CSCPicker(
showStates: true,
showCities: false,
flagState: CountryFlag.DISABLE,
dropdownDecoration: BoxDecoration(
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
color: Colors.white,
border: Border.all(color: Colors.grey.shade300, width: 1)),
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",

            ///Country Filter [OPTIONAL PARAMETER]
            countryFilter: [
              CscCountry.India,
              CscCountry.United_States,
              CscCountry.Canada
            ],

            ///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,
            ),

            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!;
              });
            },
          ),
          TextButton(
              onPressed: () {
                setState(() {
                  address = "$cityValue, $stateValue, $countryValue";
                });
              },
              child: Text("Print Data")),
          Text(address)
        ],
      ),
    ),
  ),
);

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
I must be able to select the cities and states as well after i select on the country

Screenshots
image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@http-rixhi
Copy link

I'm also facing the same issue... after selecting country there is no dropdown for state and city!!

@atvbasha
Copy link

atvbasha commented Mar 5, 2024

any solution??

@nikhil0304hande
Copy link

nikhil0304hande commented Jun 14, 2024

The value of stateValue and cityValue are nullables and hence we need to use null-aware operator and assign a default value. Replace value with value ?? "".
Example:
onStateChanged: (value) {
setState(() {
stateValue = value ?? "";
});
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants