Flutter SDK Set Background image

后端 未结 10 1752
礼貌的吻别
礼貌的吻别 2020-11-30 20:38

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 someth

10条回答
  •  無奈伤痛
    2020-11-30 21:17

    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.

提交回复
热议问题