Error: Either zero or 2 or more [DropdownMenuItem]s were detected with the same value I/flutter (18363): 'package:flutter/src/material/dropdown.dart':

后端 未结 10 1402
借酒劲吻你
借酒劲吻你 2021-01-17 13:07

Error code Hi I\'m new to flutter and have a question about dropdownbutton regarding using the same values for multiple dropdownbutton.

From my understanding from th

10条回答
  •  无人共我
    2021-01-17 13:34

    You are getting that exception because _value1 and _value2 aren't initialized and providing empty to the dropdown widget.

    You could do something like this:

    DropdownButton(
      value: _value1.isNotEmpty ? _value1 : null, // guard it with null if empty
      items: nameList.map((item) {
               return DropdownMenuItem(
                  value: item,
                  child: new Text(item),
               );
             }).toList(), 
    );
    

提交回复
热议问题