csc_picker icon indicating copy to clipboard operation
csc_picker copied to clipboard

State and cities drop down not working after selecting the country

Open Prasiddha777 opened this issue 1 year ago • 3 comments

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.

Prasiddha777 avatar Jan 15 '24 05:01 Prasiddha777

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

http-rixhi avatar Mar 04 '24 12:03 http-rixhi

any solution??

atvbasha avatar Mar 05 '24 12:03 atvbasha

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 ?? ""; }); },

nikhil0304hande avatar Jun 14 '24 06:06 nikhil0304hande