颤振对话框背景图像



我正在尝试一些奇异的Flutter对话框的实验。至于现在,我想有一个SimpleDialog(或AlertDialog)与资产图像作为背景。不幸的是,这似乎是不可能的,因为只有颜色可作为背景。我怎样才能避开这个问题,用图像填充对话框呢?

我已经看过这个答案了,但这是一个对话框中的图像。它总是有边距

你想要做的应该足够简单,你只需要确保将AlertDialogcontentPadding属性设置为零,并使用堆栈。

我还建议在你的图像周围使用一个定位,这样它就不会决定对话框的大小,否则对话框可能会在屏幕上变得尽可能大。这样做可以确保对话框的大小与另一个子(您的实际内容)相同。

showDialog(
context: context,
builder: (context) {
return AlertDialog(
backgroundColor: Colors.red,
content: Stack(
children: [
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 0,
child: Image.network(
"https://images.unsplash.com/photo-1596117803277-6142bb2ae8ef?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=2364&q=80",
fit: BoxFit.cover,
),
),
Padding(
padding: EdgeInsets.all(24),
child: Container(
height: 400,
width: 240,
color: Colors.white.withOpacity(.3),
),
)
],
),
contentPadding: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
);
},
);

最新更新