DropdownButton需要设置初始值的时候,初始值必须是显示列表里面的值,否则会导致弹出框异常。
比如说:你的DropdownButton的items属性使用的是list这个列表里面的值,那么你的初始值应该在list[index]里面取,要不就会报错。
There should be exactly one item with [DropdownButton]'s value: 0.0.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 834 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'
本文详细解析了Flutter中DropdownButton组件的正确使用方法,强调了初始值必须为items属性列表内的值,避免因错误设置导致的异常。通过实例说明如何选取正确的初始值,确保DropdownButton正常工作。
68

被折叠的 条评论
为什么被折叠?



