flutter - Overalyed 图像不会在颤动中出现在左下角
问题描述
我正在使用堆栈将图像覆盖在另一个图像上。
以下是我的代码:
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
//color: kBluePrimaryColor,
width: MediaQuery.of(context).size.width,
//height: MediaQuery.of(context).size.height * 0.23,
child: bannerimage == '' || bannerimage == null
? Image.asset('images/user.jpg')
: Image.network(
'image from api call'
fit: BoxFit.cover,
),
),
Align(
alignment: Alignment.bottomLeft,
child: Container(
//alignment: Alignment(0, -0.5),
width: 100,
height: 65,
decoration: ShapeDecoration(
shape: CircleBorder(), color: Colors.white),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: thumbnailimage == '' ||
thumbnailimage == null
? AssetImage('images/user.jpg')
: NetworkImage(
'image called using api'
))),
),
),
)
],
),
使用此代码,我得到以下输出:
我想要的是:
有人可以帮我吗?
解决方案
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
padding: EdgeInsets.only(bottom: 50), // this will give extra space below the image
//color: kBluePrimaryColor,
width: MediaQuery.of(context).size.width,
//height: MediaQuery.of(context).size.height * 0.23,
child: bannerimage == '' || bannerimage == null
? Image.asset('images/user.jpg')
: Image.network(
'image from api call'
fit: BoxFit.cover,
),
),
Positioned(
bottom: 0, // how far you want image to be from bottom of the screen
left: 10, // how far you want image to be from left of the screen
child: Container(
//alignment: Alignment(0, -0.5),
width: 100,
height: 65,
decoration: ShapeDecoration(
shape: CircleBorder(), color: Colors.white),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: thumbnailimage == '' ||
thumbnailimage == null
? AssetImage('images/user.jpg')
: NetworkImage(
'image called using api'
))),
),
),
)
],
),
推荐阅读
- git - Git选项卡完成停止在远程分支上工作
- python - 获取输出到 csv - python
- python-3.x - Python中的负切片步骤没有得到输出
- javascript - 在 useEffect 中使用 useState 时 Map 不是函数
- bash - Shell 脚本 - IFS 读取语法错误:意外重定向
- c - 来自 Linux 驱动程序的 32 字节 PCIe 事务
- django - 如何在 django admin 中获取自定义列的总和?
- android - 需要适用于 Unity 的 Facebook Audience Network 6.0.0 更新
- r - 在存在缺失数据的情况下,使用 pmin() 查找 r 中的最早日期
- firebase - 使用 Firebase Cloud Function 获取受 API 密钥保护的数据