user11065582
user11065582

Reputation:

how to set initial(default) value in dropdownButton?

How to set initial value from cache to dropdown button? have submitted button, if click submits button should add to drop-down button value. Now it's working. I need to add initial value to the drop-down button. and If add initial value and when click to submit button without selecting a value in dropdown selecting value should ant to pass

Container(
            child: ButtonTheme(
              alignedDropdown: true,
              child: DropdownButton<WorkSource>(
                isExpanded: true,
                value: _workSources,
                items: workSources.map((WorkSource value) {
                  return DropdownMenuItem<WorkSource>(
                    value: value,
                    child: Text(
                      value.description,
                      overflow: TextOverflow.ellipsis,
                    ),
                  );
                }).toList(),
                onChanged: (value) => setState(() {
                      workSourceIndex = value.id;
                      _workSources = value;
                    }),
                style: Theme.of(context).textTheme.title,

Upvotes: 0

Views: 3203

Answers (1)

Keerti Purswani
Keerti Purswani

Reputation: 5361

_workSources in your code should be the initial value. Just assign value to that in initState().

Upvotes: 1

Related Questions