[英]How to change background color of CupertinoAlertDialog?
I want create a CupertinoAlertDialog with dark background.我想创建一个带有深色背景的 CupertinoAlertDialog。
And I try to use Theme widget to solve this problem, but it doesn't work.我尝试使用 Theme 小部件来解决这个问题,但它不起作用。
Some code here:这里的一些代码:
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'),
),
],
),
);
},
);
}
Instead of using Colors.black
, use ThemeData.dark()
而不是使用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'),
),
],
),
);
},
);
}
The background color is hardcoded:背景颜色是硬编码的:
https://github.com/flutter/flutter/blob/20e59316b8b8474554b38493b8ca888794b0234a/packages/flutter/lib/src/cupertino/dialog.dart#L198 https://github.com/flutter/flutter/blob/20e59316b8b8474554b38493b8ca888794b0234a/packages/flutter/lib/src/cupertino/dialog.dart#L198
But you can create your own widget instead of default one.但是您可以创建自己的小部件而不是默认小部件。
也许你可以使用adaptive_Dialog代替它https://pub.dev/packages/adaptive_dialog
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.