标题未显示在AlertDialog小部件Flutter中

时间:2020-09-26 19:02:09

标签: flutter flutter-widget flutter-dialog

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

1 个答案:

答案 0 :(得分:0)

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();
        },
      ),
    ],

尝试一下,看看是否可行。