I want create a CupertinoAlertDialog with dark background.
And I try to use Theme widget to solve this problem, but it doesn't work.
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()
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:
But you can create your own widget instead of default one.
也许你可以使用adaptive_Dialog代替它https://pub.dev/packages/adaptive_dialog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.