Flutter setState() 不会改变

Flutter setState() doesn't change

我在更改 SearchDropdown 对象中的状态时遇到问题。如果某个项目已被选中,则该值不会更改。如果我删除它,那么我可以改变状态。我不明白问题出在哪里。

  @override
  void initState() {

    _dropdownPlatformReach =
        buildDropdownMenuItemsPlatformReach(_platformReach);
    _selectedPlatformReach = _dropdownPlatformReach[0].value;

    super.initState();
  }
Expanded(

                                  child: SearchableDropdown.single(
                                  isExpanded: true,
                                  value: _selectedPlatformReach,
                                  hint: " ",
                                  items: _dropdownPlatformReach,
                                  onChanged: (PlatformReach selectedPlatformReach) {
                                    setState(() {
                                      _selectedPlatformReach = selectedPlatformReach;
                                    });
                                  },
                                ),
                                flex: 2,
                              ),
class PlatformReach {
  String name;
  String hint;
  PlatformReach(this.name, this.hint);

  static List<PlatformReach> getPlatformReach() {
    return <PlatformReach>[
      PlatformReach('Jud Galati', '(RO, [Galati] County)'),
      PlatformReach('Jud Braila', '(RO, [Braila] County)'),
      PlatformReach('Jud Prahova', '(RO, [Ploiesti] County)'),
      PlatformReach('Jud Maramures', '(RO, [Baia Mare] County)'),
    ];
  }
}

我解决了问题。

似乎因为我在同一页面上有另一个下拉菜单,setState 没有为另一个改变。

我通过将每个下拉小部件移动到单独的文件中解决了这个问题。