Dart 颤振显示对话框,警报对话框背景渐变。
对于颜色,我可以使用Dart 颤振显示对话框,警报对话框背景渐变。,dart,flutter,Dart,Flutter,对于颜色,我可以使用dialogBackgroundColor属性为AlertDialog背景指定我自己的颜色 我想用Gradient作为我的背景。我怎么用这个装饰框是需要的东西,但我不知道用什么包装什么。有人能给我提供相同的想法或链接吗?在AlertDialog的build方法中有返回对话框(child:dialogChild,shape:shape)。在Dialog.build()-它返回材质(颜色:\u getColor(上下文),…。没有自定义,无法为AlertDialog设置渐变背景
dialogBackgroundColor
属性为AlertDialog
背景指定我自己的颜色
我想用
Gradient
作为我的背景。我怎么用这个<代码>装饰框是需要的东西,但我不知道用什么包装什么。有人能给我提供相同的想法或链接吗?在AlertDialog
的build方法中有返回对话框(child:dialogChild,shape:shape)代码>。在Dialog.build()
-它返回材质(颜色:\u getColor(上下文),…
。没有自定义,无法为AlertDialog
设置渐变背景
如果需要,我可以添加示例
另外,您也可以调用showDialog
并发送另一个小部件,而不是AlertDialog
,您可以在其中添加一个将用渐变装饰的容器。例如:
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),
);
}
}
如果您在AlertDialog
中只使用内容
而不使用标题
,那么您可以将内容包装在容器中
并使用渐变背景。我也在使用标题。因此,这在我的情况下不起作用。现在,我也可以将内容更改为有标题。但我还是在寻找更好的解决方案
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return GradientDialog();
});