【问题标题】:Title is not displayed in AlertDialog Widget Flutter标题不显示在 AlertDialog 小部件颤振中
【发布时间】:2021-01-12 19:33:47
【问题描述】:
Provider.of<Products>(context, listen: false)
      .addProducts(_editedProduct)
      .catchError((error) {
    return showDialog<Null>(
      context: context,
      builder: (ctx) {
        return AlertDialog(
          title: Text(
            'An error occurred',
          ),
          content: Text('SomethingWent Wrong'),
          actions: [
            FlatButton(
              child: Row(
                children: [
                  Icon(Icons.close),
                  Text('Close'),
                ],
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            )
          ],
        );
      },
    );
  }).then((value) {
    setState(() {
      _isLoading = false;
    });
    Navigator.of(context).pop();
  });

我能够显示警告对话框,但我无法显示标题。我找不到原因。 一切正常,只是没有显示标题。

Alert Dialog Screenshot

【问题讨论】:

  • 你的主题的标题颜色是白色的吗?只是为了确保:尝试设置标题的颜色(例如黑色)。
  • 谢谢。是的,这是我的主题配置的问题。

标签: flutter flutter-widget flutter-dialog


【解决方案1】:

我也遇到过。 给文字一个颜色,我觉得默认是白色的所以你看不到。

【讨论】:

    【解决方案2】:
    return AlertDialog(
        title: Text('AlertDialog Title'),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              Text('This is a demo alert dialog.'),
              Text('Would you like to approve of this message?'),
            ],
          ),
        ),
        actions: <Widget>[
          FlatButton(
            child: Text('Approve'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
    

    试试这个,看看它是否有效。

    【讨论】:

      猜你喜欢
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 2020-10-24
      • 2021-09-27
      • 2020-07-29
      相关资源
      最近更新 更多