altafc22 / 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.
BSD 3-Clause "New" or "Revised" License
27 stars 111 forks source link

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

Open Prasiddha777 opened 5 months ago

Prasiddha777 commented 5 months ago

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):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

http-rixhi commented 4 months ago

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

atvbasha commented 4 months ago

any solution??

nikhil0304hande commented 3 weeks ago

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