小编Adi*_*xit的帖子

路由谓词在颤振中意味着什么?

我正在使用Navigator.pushNamedAndRemoveUntil()我遇到的方法RoutePredicate

我在任何地方都找不到完美的解释RoutePredicate

有人可以解释一下吗?

flutter

6
推荐指数
1
解决办法
1557
查看次数

在 flutter 中使用 dropdownbutton 时出现“应该只有一个项目具有 [DropdownButton] 的值:Item1”错误

我试图在我的 flutter 应用程序中使用下拉菜单,但出现错误。

这是代码:

List<String> items = ["Item1", "Item2", "Item3", "Item4"];
String selectedItem = "Item1";
DropdownButton<String>(
  items: items.map(
    (txt) {
      return DropdownMenuItem<String>(
        child: Text(
          "$txt"
        ),
      );
    }
  ).toList(),
  value: selectedItem,
)
Run Code Online (Sandbox Code Playgroud)

在某些问题中,我发现我们必须首先将变量设置为列表中存在的值。我已经完全做到了,但仍然出现错误。

错误信息:

There should be exactly one item with [DropdownButton]'s value: Item1. 
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 850 pos 15: 'items == null || items.isEmpty || value == null ||
              items.where((DropdownMenuItem<T> item) {
                return item.value == …
Run Code Online (Sandbox Code Playgroud)

dart flutter

4
推荐指数
1
解决办法
4448
查看次数

标签 统计

flutter ×2

dart ×1