如何在Flutter中设置背景图像? [英] How do I Set Background image in Flutter?

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

问题描述

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

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'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中设置背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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