我正在使用简单的 Hive 数据库制作一个移动 Flutter 应用程序。我的 Hive 框中有一些 Account 对象,我需要将其作为可选列表显示给用户(例如在 DropdownButton 中)。我该如何实施?
我试图将值作为列表提供,但出现错误The argument type 'List<Account>' can't be assigned to the parameter type 'List<DropdownMenuItem<Account>>'.
DropdownButton(
items: Hive.box<Account>('accounts').values.toList(),
),
编辑:已经解决了 - 这是解决方案
DropdownButton(
items: Hive.box<Account>('accounts').values.toList().map((Account acc) {
return DropdownMenuItem<Account>(
value: acc,
child: Text(acc.name),
);
}).toList(),
),