Reputation: 338
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'),
),
],
),
);
},
);
}
Upvotes: 13
Views: 12975
Reputation: 101
For dark mode with you CupertinoAlertDialog
, can do the following:
bool isAppInDarkMode(BuildContext context) {
final brightness =
WidgetsBinding.instance.platformDispatcher.platformBrightness;
return brightness == Brightness.dark;
}
showDialog() {
showCupertinoDialog(
context: context,
builder: (context) {
final brightness = isAppInDarkMode(context) ? Brightness.dark : Brightness.light;
return CupertinoTheme(
data: CupertinoThemeData(
brightness: brightness,
),
child: CupertinoAlertDialog(
title: Text(title),
content: Text(subtitle),
actions: actionsWidgets,
),
);
},
);
}
Upvotes: 1
Reputation: 1
Maybe you can use adaptive_ Dialog instead of it https://pub.dev/packages/adaptive_dialog
Upvotes: -1
Reputation: 111
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'),
),
],
),
);
},
);
}
Upvotes: 9
Reputation: 16185
The background color is hardcoded:
But you can create your own widget instead of default one.
Upvotes: 3