【问题标题】:How to display dialog box inside textFieldSearch after selecting an item in search dropdown in flutter如何在 flutter 中选择搜索下拉列表中的项目后在 textFieldSearch 中显示对话框
【发布时间】:2022-12-09 22:13:17
【问题描述】:

我正在从 textFieldSearch 中搜索,从 searchDropdown 中选择一个项目后我想要一个弹出窗口

我试过的-> 在 textFieldSearch getSelected 属性中,我尝试调用 AlertDialog,但它没有显示。 我在期待什么-> 从 searchDropDown 选择一个项目后,我想要一个弹出窗口

【问题讨论】:

  • 你能提供一些你以前试过的代码吗

标签: flutter textfield flutter-alertdialog


【解决方案1】:

试试这个,首先创建一个 AlertDialog 小部件,当从搜索下拉列表中选择一个项目时,您希望显示它。您可以根据需要自定义对话框的内容和按钮:

final dialog = AlertDialog(
  title: Text('Selected Item'),
  content: Text('You have selected an item from the search dropdown.'),
  actions: [
    FlatButton(
      child: Text('OK'),
      onPressed: () {
        // Dismiss the dialog
      },
    ),
  ],
);

然后,在 textFieldSearchgetSelected 属性中,使用刚刚创建的 AlertDialog 小部件调用 showDialog 方法:

textFieldSearch: TextFieldSearch(
  getSelected: (String selected) {
    // Show the dialog
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return dialog;
      },
    );
  },
),

这应该适合你! 快乐编码

【讨论】:

    猜你喜欢
    • 2021-06-18
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    相关资源
    最近更新 更多