flutter - 为什么两个容器之间有一条白线颤动
问题描述
我正在为我的应用程序制作一个抽屉,它在列小部件中有 2 个容器,这些容器之间似乎有一条线破坏了外观,我已经为上部容器尝试过这个
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
这对于下部容器
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
这条线仍然存在。如何删除该行,任何帮助将不胜感激。这是抽屉的代码:
Drawer(
child: Column(
children: <Widget>[
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
child: Stack(
children: <Widget>[
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fitWidth,
),
Positioned(
left: globals.widthofdevice * 0.07,
bottom: 20,
child: Text(
globals.username,
style: GoogleFonts.quicksand(
textStyle: TextStyle(
// fontWeight: FontWeight.w700,
fontSize: 32,
color: Colors.white,
),
),
),
)
],
),
),
Container(
height: globals.heightofdevice * 0.70,
margin: EdgeInsets.only(top: 0),
padding: EdgeInsets.only(top: 0),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.redAccent, Colors.white],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Stack(children: <Widget>[
Image.asset(
'./images/uni.jpg',
fit: BoxFit.cover,
width: double.infinity,
),
Column(
children: <Widget>[
listTileBuilder(Icons.history, 'History'),
listTileBuilder(Icons.info_outline, 'About the app'),
listTileBuilder(Icons.account_circle, 'Logout'),
listTileBuilder(Icons.exit_to_app, 'Exit'),
],
),
]),
)
],
),
)
您可以清楚地看到这张图片中的问题
解决方案
问题很可能是您的顶部小部件的图像设置为fit: BoxFit.fitWidth,
. 由于它试图完全填充水平平面,因此一旦完成它就会停止并且不会垂直缩放以覆盖剩余的空白区域。
要使用颜色填充图像未占用的容器空间,使其不是白线,您可以尝试以下操作(将背景更改为黑色):
Container(
height: globals.heightofdevice * 0.30,
width: double.infinity,
margin: EdgeInsets.only(bottom: 0),
padding: EdgeInsets.only(bottom: 0),
colors: Colors.black, // Added color
child: Stack(
...
),
),
或者尝试使图像占用容器的所有可用空间,无论图像的大小和纵横比如何,您都可以更改 BoxFit 以填充:
Image.asset(
'./images/drawerbackground.jpg',
fit: BoxFit.fill, // BoxFit fill
),
推荐阅读
- eyeshot - 如何在 docker 中运行 eyeshot
- c++ - 为什么使用 Linux 和 Visual Studio 的相同代码的输出不同?
- flutter - 如何定义一个与 Dart/Flutter 中的另一个类完全相同的类
- c# - Helixtoolkit UWP TransformManipulator3D
- python-3.x - 将 requests.models.Response 转换为 flask.wrappers.Response 1:1
- c# - 使用多个集线器实例的 ASP.NET Core SignalR
- python - 使用 Googletrans 库自动翻译列
- javascript - 如何结合 jQuery SlimScroll 和 sortableUI?
- google-sheets - 在 Google Sheet 中查询条件中的数组
- amazon-web-services - 在没有凭据的情况下使用 aws-sdk