Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 颤振显示对话框,警报对话框背景渐变。_Dart_Flutter - Fatal编程技术网

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();
    });