0

I want to make DropdownButtonFormField that shows cities like this:

final List<String> cities = ['London', 'New York', 'Paris', 'Shanghahai', 'Tokyo'];

String _currentCity;

DropdownButtonFormField(
            value: _currentCity ?? ' ',
            decoration: textInputDecoration,
            items: cities.map((city) {
              return DropdownMenuItem(
                value: city,
                child: Text('$city City '),
              );
            }).toList(),
            onChanged: (val) => setState(() => _currentCity = val ),
          ),

But when I try to show these Strings I get red screen error : enter image description here

and If I changed the Strings inside the List to numbers it works well:

 final List<String> cities = ['0', '1', '2', '3', '4'];

Can someone tell me what is wrong with it although I use List of strings

1 Answer 1

1

You can try set _currentCity for default value?

String _currentCity = 'London';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.