颤振 - 飞镖 - 使图像全屏大小



我希望我的图像适合屏幕,现在我有:

return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Stack(
children: <Widget>[
Center(
child: FittedBox(
fit: BoxFit.fill,
child: Image.file(File(_path)),
)
),

这不起作用,图像不适合全屏。

我读了DecorationImage,经过一些测试,可以让图像填满全屏。但是我没有找到任何有关如何将其与Image.file一起使用的信息.可能吗?

以下是我在应用程序中放置背景的方法:

Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(_path),
fit: BoxFit.cover,
),
),
),
... Other children
]
)

删除 safeArea 并用容器包装图像小部件。 使用mediaQuery制作与屏幕大小相同的高度和宽度的容器。 我在这里看不到 Center(( 的用法。

Container(
height:MediaQuery.of<context>.size.height,
width:MediaQuery.of<context>.size.width,
child: Stack(
children: <Widget>[
Center(
child: FittedBox(
fit: BoxFit.fill,
child: Image.file(File(_path)),
)

只需将中心小部件替换为容器并将其高度,宽度标记为无穷大

body: SafeArea(
child: Stack(children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
child: FittedBox(
fit: BoxFit.cover,
child: Image.file(File(_path)),
),
),
),
]),
));

最新更新