flutter - 如何在 Flutter 的 AlertDialog 上设置背景图像?
问题描述
我想单击带有 InkWell 的卡片,该卡片显示图像,因为它是一个带有文本的 AlertDialog。我认为问题可能是在 AlertDialog 上将图像设置为背景,所以我可以在上面写,但我只能使用 backgroundColor。
这是我的想法,但我无法将图像设置为 AlertDialog 的背景。
child: InkWell(
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Container(...),
);
},
);
},
child: Container(...),
),
解决方案
在这里尝试一下,我可能没有InkWell
您想要的位置,但这会导致图像顶部的居中文本。如果您不希望图像和文本处于相同的对齐方式,请查看Positioned小部件。
Card(
child: InkWell(
child: Text('This is some text in a card'),
onTap: () => showDialog(
context: context,
builder: (context) => AlertDialog(
content: Stack(
alignment: Alignment.center,
children: <Widget>[
Image.asset(
'Path to image',
height: 200,
fit: BoxFit.cover,
),
Text(
'This Is Some Text',
style: TextStyle(
fontSize: 24,
),
),
],
),
),
),
),
),
推荐阅读
- python - 使用 Python kivy 创建游戏开始菜单
- popup - 单击按钮或文本时弹出窗口 SP 2010
- mysql - Spring Data JPA 方法命名包含对双值的查询
- php - 带有 4 个波斯字符的 ksort 关联数组问题
- javascript - 按钮后自动插入 div 但在新行中
- android - Flutter text-to-speech(Dart 语言):如何在 tts 引擎读取文本时为文本添加背景颜色?
- asp.net-mvc - 发布应用程序时的.Net Core React SPA路由问题
- r - 将 KableExtra 表的字体样式从 Helevica 更改为 Arial
- python-3.x - 尝试导入样条曲线时的 SciPy 导入错误
- python - 将不完整的日期转换为日期时间 dtype