如何更改CupertinoAlertDialog的背景颜色?

11

我希望创建一个带有黑色背景的CupertinoAlertDialog对话框。

我尝试使用Theme小部件来解决这个问题,但是它并没有起作用。

以下是一些代码:

showDialog() {
    showCupertinoDialog(
        context: context,
        builder: (context) {
          return Theme(
            data: ThemeData(
                dialogBackgroundColor: Colors.black,
                dialogTheme: DialogTheme(backgroundColor: Colors.black)),
            child: CupertinoAlertDialog(
            title: Text('Title'),
            content: Text('Some message here'),
            actions: <Widget>[
               FlatButton(
                 onPressed: () {
                   Navigator.of(context).pop();
                 },
                 child: Text('OK'),
               ),
             ],
           ),
         );
       },
     );
  }

enter image description here

3个回答

9

不要使用Colors.black,而是使用ThemeData.dark()

showDialog() {
    showCupertinoDialog(
        context: context,
        builder: (context) {
          return Theme(
            data: ThemeData.dark(),
            child: CupertinoAlertDialog(
            title: Text('Title'),
            content: Text('Some message here'),
            actions: <Widget>[
               FlatButton(
                 onPressed: () {
                   Navigator.of(context).pop();
                 },
                 child: Text('OK'),
               ),
             ],
           ),
         );
       },
     );
  }

3

-1

欢迎提供解决方案的链接,但请确保您的答案即使没有链接也是有用的:添加链接周围的上下文,以便您的同行用户知道它是什么以及为什么存在,然后引用您链接到的页面中最相关的部分,以防目标页面不可用。仅包含链接的答案可能会被删除。还要阅读如何回答 - user10992464
这个包是 CupertinoAlertDialog 的封装,因此背景颜色是硬编码的。 - BambinoUA

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接