flutter - Flutter 对话框背景图片
问题描述
我正在尝试一些具有异国情调的 Flutter 对话框的实验。至于现在,我想要一个SimpleDialog
(或AlertDialog
)以资产图像作为背景。不幸的是,这似乎是不可能的,因为只有颜色可用作背景。我怎样才能绕过这个问题并用图像填充我的对话框?
我已经看过这个答案,但这是对话框内的图像。它总是有边距
解决方案
您要做的应该足够简单,您只需确保将 的contentPadding
属性设置AlertDialog
为零,并使用堆栈。
我还建议在您的图像周围使用定位,这样它就不会决定对话框的大小,否则对话框可能会在屏幕上变得尽可能大。这样做可以确保对话框的大小适合另一个孩子(您的实际内容)。
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)),
);
},
);
推荐阅读
- postgresql - Nestjs - QueryFailedError:uuid 类型的输入语法无效
- python - 如何查看使用 Angular JS 生成的网页内容?
- oauth-2.0 - Oauth2 SSO 中的 Ejabberd 参与者是否有客户端
- python - 通过全局函数调用嵌套函数?
- python - Python while循环在时间间隔内执行
- python - 从 sklearn.metrics 导入 Max_Error
- android - 在片段中获取 ViewModel 时,我应该将“viewModelStore”还是“this”作为 ViewModelStore 提供给 ViewModelProvider() 方法
- google-sheets - 将宏分配给单元格而不是绘图/文本框
- javascript - 将元素对象复制到另一个对象Javascript / Angular
- c++ - 如何编写一个 C++ 正则表达式,根据某些条件识别字符串中选定的浮点数或整数?