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'),
),
],
),
);
},
);
}
To change the background color of AlertDialog in Flutter, set the backgroundColor property of AlertDialog with the required color. Following is a sample AlertDialog whose background color is changed to Colors.green. Sample code snippet to change the background color of AlertDialog widget in Flutter is AlertDialog( backgroundColor: Colors.green, ...
The CupertinoAlertDialog shows an alert with a set of two choices when CupertinoButton is pressed. CupertinoPopupSurface, which is a generic iOS-style popup surface that holds arbitrary content to create custom popups. CupertinoDialogAction, which is an iOS-style dialog button. AlertDialog, a Material Design alert dialog.
CupertinoPopupSurface, which is a generic iOS-style popup surface that holds arbitrary content to create custom popups. CupertinoDialogAction, which is an iOS-style dialog button.
Color can be used to highlight important information in your report or differentiate sections. You can add, change, or remove background colors for an entire report section or format records in a table.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With