Flutter SDK设置背景图片 [英] Flutter SDK Set Background image

查看:88
本文介绍了Flutter SDK设置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为主页设置背景图像。我从屏幕开始获取图像位置,并填充宽度而不是高度。
我在代码中缺少什么吗?有抖动的图像标准吗?图片会根据每部手机的屏幕分辨率缩放吗?

I am trying to set a background image for the home page. I am getting the image place from start of the screen and filling the width but not the height. Am I missing something in my code? Are there image standards for flutter? Do images scale based on each phone's screen resolution?

class BaseLayout extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    return new Scaffold(
      body: new Container(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            new Image.asset("assets/images/bulb.jpg") 
          ]
        )
      )
    );
  }
}


推荐答案

I我不确定我是否理解您的问题,但是如果您希望图像填充整个屏幕,则可以使用 DecorationImage ,适合 BoxFit.cover

I'm not sure I understand your question, but if you want the image to fill the entire screen you can use a DecorationImage with a fit of BoxFit.cover.

class BaseLayout extends StatelessWidget{
  @override
  Widget build(BuildContext context){
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/images/bulb.jpg"),
            fit: BoxFit.cover,
          ),
        ),
        child: null /* add child content here */,
      ),
    );
  }
}

对于第二个问题,这是指向文档有关如何将分辨率相关的资产图像嵌入到您的应用中。

For your second question, here is a link to the documentation on how to embed resolution-dependent asset images into your app.

这篇关于Flutter SDK设置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆