flutter - 如何在颤动中制作响应式容器
问题描述
我想让我的容器响应图像大小,但不知何故它不起作用。
下面是我制作的容器-:
Container(
height: size.height * 0.7,
width: size.width * 0.95,
decoration: BoxDecoration(
// borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)),
image: DecorationImage(
image: AssetImage('assets/vir.gif'),//widget.user.imgUrl),
fit: BoxFit.contain,
),
),
child: Container(
decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(color: Colors.black12, spreadRadius: 0.5),
],
),
),
),
在这里,如果图像的高度与容器相同,则很好,但如果高度较小,则我可以看到我不想要的背景。
即使我在容器中添加任何信息,高度仍然是固定的并且不会根据内容进行调整。
下面是另一个例子-:
Container(
height: size.height * 0.2,
width: size.width * 0.95,
decoration: BoxDecoration(
color: Colors.pink[100],
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Wrap(
spacing: 10,
children: [
Chip(
elevation: 5,
label: Text('Height'),
labelStyle: TextStyle(
color: Colors.white,
fontSize: 17,
),
backgroundColor: Colors.pinkAccent,
deleteIcon: Icon(Icons.height),
// labelPadding: EdgeInsets.symmetric(horizontal: 10),
),
Chip(
elevation: 5,
label: Text('Active'),
labelStyle: TextStyle(
color: Colors.white,
fontSize: 17,
),
backgroundColor: Colors.pinkAccent,
labelPadding: EdgeInsets.symmetric(horizontal: 10),
),
Chip(
elevation: 5,
label: Text('Start Sign'),
labelStyle: TextStyle(
color: Colors.white,
fontSize: 17,
),
backgroundColor: Colors.pinkAccent,
labelPadding: EdgeInsets.symmetric(horizontal: 10),
),
]
),
)
],
),
),
在这里,如果我添加或删除任何内容,那么我必须手动增加或减少大小。谁能帮我这个?
解决方案
推荐阅读
- javascript - React:遍历对象并更改某些属性
- ios - 有没有办法在使用 Swift 5 完成功能后重新加载视图控制器?
- tensorflow - 如何进行更快的深度强化学习训练
- nginx - 如何使用多个代理配置 Nginx
- android - 如何为这些创建通用方法?
- javascript - Javascript:在表单提交的url中查找和替换字符串
- r - 跨行求和,但仅满足条件的单元格
- javascript - JQuery 在延迟删除类上无法正常工作
- c++ - 将 json++ 实现转换为使用 rapidJSON:处理字符串和 wstring 的混合
- git - 无法在 Azure Devops 管道中推送 git 标签