【问题标题】:flutter: how to pass value to a dialogbox?颤振:如何将值传递给对话框?
【发布时间】:2021-09-28 12:06:17
【问题描述】:

假设我有一个显示如下对话框的功能,如何让它接受一个值并将其显示在对话框上?代码示例后的错误消息如下,我不明白它的含义。谢谢你

  Future _showMyDialog(String message) async {
    return showDialog(
      context: context,
      barrierDismissible: true, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('Warning'),
          content: SingleChildScrollView(
            child: ListBody(
              children: const <Widget>[
                Text(message),
              ],
            ),
          ),
          actions: <Widget>[
            TextButton(
              child: const Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

错误信息: 如果 [style] 参数为 null,则文本将使用最近的封闭 [DefaultTextStyle] 中的样式。

[data] 参数不能为空。

[overflow] 属性的行为受 [softWrap] 参数的影响。如果 [softWrap] 为 true 或 null,则不会呈现导致溢出的字形以及随后的字形。否则,它将与给定的溢出选项一起显示。

【问题讨论】:

  • 您的代码工作正常,没有任何错误/问题或警告

标签: flutter dart


【解决方案1】:

@SteveT 如果您从 Listbody 的子项中删除了 const,那么您的 issue 将被删除。

 Future _showMyDialog(String message) async {
    return showDialog(
      context: context,
      barrierDismissible: true, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('Warning'),
          content: SingleChildScrollView(
            child: ListBody(
              children: <Widget>[
                Text(message),
              ],
            ),
          ),
          actions: <Widget>[
            TextButton(
              child: const Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 2013-07-06
    • 2013-02-25
    • 1970-01-01
    • 2022-11-11
    • 2020-02-13
    • 1970-01-01
    相关资源
    最近更新 更多