对于颜色,我可以使用dialogBackgroundColor
属性为AlertDialog
设置自己想要的背景颜色。
我希望使用Gradient
作为我的背景。我该怎么做?需要使用DecoratedBox
,但不知道该将什么内容包含在其中。是否有人能给我建议或相关链接?
class GradientDialog extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _GradientDialogState();
}
}
class _GradientDialogState extends State<GradientDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
content: Container(
padding: const EdgeInsets.all(8.0),
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: AppColors.BG_GRADIENT,
begin: Alignment.topCenter,
end: Alignment.bottomCenter)),
child: YourContentInside(),
),
contentPadding: EdgeInsets.all(0.0),
);
}
}
使用以下方法打开
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return GradientDialog();
});
AlertDialog
的build
方法中,有return Dialog(child: dialogChild, shape: shape);
。在Dialog.build()
中,它返回Material(color: _getColor(context), ...
。没有办法在不进行自定义的情况下为AlertDialog
设置渐变背景。showDialog
并发送另一个小部件,而不是AlertDialog
。
AlertDialog
中仅使用content
而没有title
,那么您可以将内容包装在具有渐变背景的Container
中。 - Andrii Turkovskyi