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

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

问题描述

我正在尝试为主页设置背景图像.我从屏幕开始获取图像位置并填充宽度但不填充高度.我的代码中遗漏了什么吗?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") 
          ]
        )
      )
    );
  }
}

推荐答案

我不确定我是否理解您的问题,但是如果您希望图像填满整个屏幕,您可以使用 DecorationImageBoxFit.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 中设置背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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