【问题标题】:Handle Event if dropdown gets closed when tap outside of the dropdown flutter如果在下拉菜单颤动之外点击时下拉菜单关闭,则处理事件
【发布时间】:2023-02-16 00:02:08
【问题描述】:

我挑战颤动的行为。我使用 dropDownButton 和 DropDownMenuItems 创建了一个普通的下拉菜单。 当其中一个项目被点击时,我当然可以处理。但是在下拉列表旁边单击时,我无法找到如何处理该行为。所以下拉菜单关闭但我想执行一个函数。

你有什么建议吗? 非常感谢!

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您需要在下拉列表中添加键。例子 :

    late GlobalKey Key;   // this is your key to control pop 
    
    @override
    void initState() {
        super.initState();
        Key = GlobalKey();
    }
    

    DropdownButton<Boat>(
        key: Key,
        ...)
    

    弹出只是调用--->

    GestureDetector(
        onTap: () {
            Navigator.pop(Key.currentContext)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      • 2017-03-23
      • 2021-11-17
      • 2016-06-13
      相关资源
      最近更新 更多