【问题标题】:Flutter setState() doesn't changeFlutter setState() 不会改变
【发布时间】:2020-12-04 04:25:08
【问题描述】:

我在更改 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)'),
    ];
  }
}

【问题讨论】:

    标签: flutter dart mobile native


    【解决方案1】:

    我解决了这个问题。

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

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

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2023-01-14
      • 2022-01-06
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 2020-12-27
      相关资源
      最近更新 更多