[Flutter 오류 해결하기] - Either zero or 2 or more [DropdownMenuItem]s were detected with the same value


[Flutter 오류 해결하기] - Either zero or 2 or more [DropdownMenuItem]s were detected with the same value

해당 문제는 DropDownButton이 사용하는 Value 값이 item 목록에 없으면 발생하는 오류다. 아래 코드를 보며 알아보자. 위 코드 속 DropDownButton 위젯은 qFactor 변수로 value 값을 초기 설정하면서 시작한다. 그리고 items에는 DropDownButton에서 표시할 아이템들이 들어가게된다. 앞서 본 value 값이 items 목록에 없으면 해당 오류가 발생한다. 예를 들어 위에서 int qFactor = 0; 으로 초기화했다고 가정해보자. DropDownButton 위젯이 사용하는 items 리스트는 1부터 시작하는 정수들로 이루어져있어 0이 없다. 하지만 DropDownButton의 초기값 역할을 하는 qFactor는 0으로 초기화되어 있기 때문에 에러가 발생한다. items 리스트..........



원문링크 : [Flutter 오류 해결하기] - Either zero or 2 or more [DropdownMenuItem]s were detected with the same value