0

I coded a dropdownbutton so it gets the items from a database from back4app, it shows the user the items that he saved on said database. But when I try to hold the state for the selection of said item, it shows a blank dropdownbutton, eventhough it is showing the items from the database. Here is the error: [A value of type 'String' can't be assigned to a variable of type 'List'. Try changing the type of the variable, or casting the right-hand type to 'List']. What did I do wrong?

DropdownButton<String>(
              items: dropdownItems.map((ParseObject value) {
                return DropdownMenuItem<String>(
                  value: value.get<String>('numeracao')!,
                  child: Text(value.get<String>('numeracao')!),
                );
              }).toList(),
              onChanged: (String? newValue) {
                setState(() {
                  dropdownItems = newValue!;
                });
              },
            ),
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Giorno
  • 1
  • 1

1 Answers1

0

You need a new var to hold the current value. Let's say String dropdownValue. Then your DropownButton should look something like this:

DropdownButton<String>(
              value: dropdownValue,
              items: dropdownItems.map((ParseObject value) {
                return DropdownMenuItem<String>(
                  value: value.get<String>('numeracao')!,
                  child: Text(value.get<String>('numeracao')!),
                );
              }).toList(),
              onChanged: (String? newValue) {
                setState(() {
                  dropdownValue = newValue!;
                });
              },
            ),
Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11