颤振变化对话框背景颜色

4 dart flutter

我使用的dialogBackgroundColor属性仍然是颜色没有改变.谁能告诉我如何更改对话框的背景颜色?

小智 23

如果您使用材质 3,您应该将属性 surfaceTintColor 设置为透明

Dialog(
   backgroundColor: MyColors.white,
   surfaceTintColor: Colors.transparent,
   child: ... )
Run Code Online (Sandbox Code Playgroud)

这对我有用:)


Cop*_*oad 12

您现在可以使用backgroundColor属性AlertDialog来更改颜色。

AlertDialog(
  backgroundColor: Colors.orange,
  ...
)
Run Code Online (Sandbox Code Playgroud)


小智 7

你需要用你DialogBuilder这个样子.之后dialogBackgroundColor会产生影响.

Theme(
  data: ThemeData(dialogBackgroundColor: Colors.orange),
  child: Builder(
    builder: (context) {
      return RaisedButton(
        onPressed: () {
          showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                title: Text("Dialog title"),
              );
            },
          );
        },
        child: Text("Show dialog"),
      );
    },
  ),
)
Run Code Online (Sandbox Code Playgroud)


Ahm*_*aza 6

您现在可以使用AlertDialog 的backgroundColor 属性来更改颜色。

    showDialog(
   context: context,
   builder: (BuildContext context) {
       return AlertDialog(
         shape: RoundedRectangleBorder(
         borderRadius: BorderRadius.all(Radius.circular(20.0))),
         backgroundColor: Colors.green,
   content: Container(...)
),
}),
Run Code Online (Sandbox Code Playgroud)


Cop*_*oad 5

您可以在不使用Builder.

这是示例。

@override
Widget build(BuildContext context) {
  return RaisedButton(
    onPressed: () {
      showDialog(
        context: context,
        builder: (context) {
          return Theme(
            data: Theme.of(context).copyWith(dialogBackgroundColor: Colors.orange),
            child: AlertDialog(
              title: Text("Dialog Title"),
            ),
          );
        },
      );
    },
    child: Text("Show dialog"),
  );
}
Run Code Online (Sandbox Code Playgroud)