1

I got issue to display value after select option... It always display Type All. I've follow from this answer but still got the problem.

enter image description here

DropdownButton(
    hint: Text('Filter All Type'),
    value: _typeDataL,
    onChanged: (_newValue) {
        setState(() {
            _typeDataL = _newValue;
            // print(typeDataL);
        });
        print(_newValue);
    },
    items: typeDataL.map((value) {
        return DropdownMenuItem(
            value: value,
            child: new Text(value),
        );
    }).toList(),
),
Mirko Raimo
  • 1,469
  • 1
  • 12
  • 19
Fash
  • 309
  • 1
  • 13

1 Answers1

3

try below code,

String? selectedValue = "Your init value";
var typeDataL = ["Your init value", "Option1", "Option2", "Option3"];

 DropdownButton(
              hint: const Text('Filter All Type'),
              value: selectedValue,
              onChanged: (newValue) {
                setState(() {
                  selectedValue = newValue;
                });
              },
              items: typeDataL.map((value) {
                return DropdownMenuItem(
                  value: value,
                  child: Text(value),
                );
              }).toList(),
            ),

Your valueList should contain initial value, same as initial selectedValue and valueList should not contain duplicate values.

Khyati Modi
  • 630
  • 1
  • 9
  • 19