alertDialog 不会出现在 flutter 中

alertDialog won't appear in flutter

当长按执行 _selectionAlert 时,我有一个列表项,它有两个按钮,一个用于删除,一个用于编辑(参见图片)。删除工作正常但是当我按下编辑它应该执行 _editAlert 应该显示另一个 alertDialog 但是当我点击它时没有任何反应这里有什么问题?
这负责在 _selectionAlert

中显示警报对话框
TextButton( // refer code bellow
    child: Text('Edit', style: TextStyle(color: Colors.grey)),
        onPressed: (){
            _editAlert();
            Navigator.of(context).pop();
        },
)

长按项目时运行以下代码:

void _selectionAlert(){
      var selItem = AlertDialog(
        title: Text('What you want to do?'),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            TextButton(       // ignore this it is for deletion this works fine
              child: Text('Delete', style: TextStyle(color: Colors.red)),
              onPressed: (){
                _deleteItem();
                Navigator.of(context).pop();
              },
            ),
            TextButton( 
              child: Text('Edit', style: TextStyle(color: Colors.grey)),
              onPressed: (){
                _editAlert();      // this line should call _editAlert
                Navigator.of(context).pop();
              },
            )
          ],
        ),
      );
      showDialog(
        context: context,
        builder: (BuildContext context){
          return selItem;
      }
    );
  }  

以上代码表示:

void _editAlert(){   // edit alertDialog
    var editItem = AlertDialog(
      title: Text('Edit'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          TextField(
            decoration: InputDecoration(
              hintText: 'Edit Item',
            ),
            controller: addeditem,
          ),
          TextButton(
            child: Text('Done'),
            onPressed: (){
              _editItem();
              Navigator.of(context).pop();
            }
          )
        ],
      ),
    );
    showDialog(
      context: context,
      builder: (BuildContext context){
        return editItem;
      }
    );
  }

PS:编辑按钮是灰色的按钮肯定是可以点击的,我正在 google chrome.
上测试 此致

尝试在您的 _editAlert 方法中添加 return 语句

_editAlert(){   // edit alertDialog
    var editItem = AlertDialog(
      title: Text('Edit'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          TextField(
            decoration: InputDecoration(
              hintText: 'Edit Item',
            ),
            controller: addeditem,
          ),
          TextButton(
            child: Text('Done'),
            onPressed: (){
              _editItem();
              Navigator.of(context).pop();
            }
          )
        ],
      ),
    );
    return showDialog(                //like that
      context: context,
      builder: (BuildContext context){
        return editItem;
      }
    );
  }


另外你的方法是对的,你可以使用弹出来关闭上一个弹出窗口。