flutter - 如何更改 CupertinoAlertDialog 的背景颜色?
问题描述
我想创建一个深色背景的 CupertinoAlertDialog。
我尝试使用主题小部件来解决这个问题,但它不起作用。
这里有一些代码:
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'),
),
],
),
);
},
);
}
解决方案
而不是使用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'),
),
],
),
);
},
);
}
推荐阅读
- ios - 在按钮上打开 ViewController
- lwc - Lightning Web 组件专家超级徽章:挑战 7 抛出错误
- android - Android后台BLE信标扫描
- c# - 对包含多个查询的方法进行单元测试
- python - 如何从这样设置的 python 目录导入模块?
- android - 获取用户选择的文件的名称和路径,而不管它在Android中的位置[在内部或外部存储器中]?
- javascript - 在现有的 android 应用程序中运行 RN View 会出现错误无法加载脚本
- git - 推荐的 git 工作流程
- reactjs - React Material UI 选项卡 关闭
- reactjs - (React Native)Null 不是对象(评估 'NativeMqtt.new 客户端)