在扑朔迷离/飞镖中满足条件时,如何执行功能?

发布于 2025-02-13 23:36:36 字数 1051 浏览 0 评论 0原文

我有一个功能:

  //Alert Dialog about questions and answers
  void _showAlertDialog() {

    // set up the buttons
    Widget Answer1Button = TextButton(
      child: Text(_listData[_listCount][3]),
      onPressed:  () {},
    );
    Widget Answer2Button = TextButton(
      child: Text(_listData[_listCount][4]),
      onPressed:  () {},
    );

    // set up the AlertDialog
    AlertDialog alert = AlertDialog(
      // title: Text(),
      content: Text(_listData[_listCount][2]),
      actions: [
        Answer1Button,
        Answer2Button,
      ],
    );

    // show the dialog
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

当我单击不同位置进行测试的按钮时,它可以很好地工作。但是如何使其在以下条件下运行:

  void _nextCSV() {
    setState(() {
      _listData = _listData;
      _listData[_listCount][2] == "" ? _showAlertDialog : print('False');
    });
  }

谢谢。

I have a function:

  //Alert Dialog about questions and answers
  void _showAlertDialog() {

    // set up the buttons
    Widget Answer1Button = TextButton(
      child: Text(_listData[_listCount][3]),
      onPressed:  () {},
    );
    Widget Answer2Button = TextButton(
      child: Text(_listData[_listCount][4]),
      onPressed:  () {},
    );

    // set up the AlertDialog
    AlertDialog alert = AlertDialog(
      // title: Text(),
      content: Text(_listData[_listCount][2]),
      actions: [
        Answer1Button,
        Answer2Button,
      ],
    );

    // show the dialog
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

It works great when I click on the button in the different place for testing. But how to make it run under the following condition:

  void _nextCSV() {
    setState(() {
      _listData = _listData;
      _listData[_listCount][2] == "" ? _showAlertDialog : print('False');
    });
  }

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白昼 2025-02-20 23:36:36

您缺少()

  void _nextCSV() {
    setState(() {
      _listData = _listData;
      _listData[_listCount][2] == "" ? _showAlertDialog() : print('False');
    });
  }

,但是即使在setState内,也可以使用,以防。

编辑:

如果您要忽略然后 else 块,则可以放置null

  condition ? null : result;
  condition ? result : null;

You are missing the ()

  void _nextCSV() {
    setState(() {
      _listData = _listData;
      _listData[_listCount][2] == "" ? _showAlertDialog() : print('False');
    });
  }

But even inside the setState you can use if in case you want to.

Edited:

In case you want to ignore the then or the else block you could just put null.

  condition ? null : result;
  condition ? result : null;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文