如何用图像填充整个屏幕,以便也包括圆角?

问题描述 投票:0回答:1

我正在尝试创建初始屏幕。背景上的图像(带帽的脸后面)应该填充整个屏幕,但不能填充整个屏幕。屏幕的左侧和右侧都有插图。我的猜测是;由于我正在三星银河S9上进行测试,因此MediaQuery.of(context).size中未包含圆形的屏幕边缘。我尝试过使用removeViewPadding和removeViewInsets,但无法正常工作。我该怎么办?

启动画面的当前状态:enter image description here

我的小部件build()函数:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
//        width: MediaQuery.of(context).removeViewInsets(
//         removeLeft: true,
//         removeRight: true,
//         removeBottom: true,
//         removeTop: true
//        ).size.width,
//        height: MediaQuery.of(context).removeViewInsets(
//          removeLeft: true,
//          removeRight: true,
//          removeBottom: true,
//          removeTop: true
//        ).size.height,
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Image.asset(
              Assets.splash_screen_background,
              fit: BoxFit.fill,
            ),
            Image.asset(
              Assets.logo,
              scale: 4,
            ),
          ],
        ),
      ),
    );
  }
flutter flutter-layout
1个回答
0
投票

尝试使用double.infinity将高度拉伸到画布或父窗口小部件的最大可能高度

Container(
    width: double.infinity,
    height:double.infinity,
    child: Stack(
      alignment: Alignment.center,
      children: <Widget>[
        Image.asset(
          Assets.splash_screen_background,
          fit: BoxFit.fill,
        ),
        Image.asset(
          Assets.logo,
          scale: 4,
        ),
      ],
    ),
  ),
);
© www.soinside.com 2019 - 2024. All rights reserved.