How to show image from network in flutter BoxDecoration?

前端 未结 2 1770
感动是毒
感动是毒 2021-02-01 16:41

I want to show an image of the network in BoxDecoration. But its showing error

\"The argument type \'image\' can\'t be assigned to the parameter type \'i

相关标签:
2条回答
  • 2021-02-01 17:28

    I've resolved the issue, it can be achieved using this code.

    decoration: BoxDecoration(
          image: DecorationImage(image: NetworkImage("urlImage"),
          fit: BoxFit.cover)
        ),
    
    0 讨论(0)
  • 2021-02-01 17:31

    Ammy's answer is right. However I would like to the answer my experience of using BoxDecoration().

    To apply background image either from the Internet or from assets in Flutter app, we can use DecorationImage() class in image property of BoxDecoration().

    Below is a code snippet, where background image is applied from an image from a URL in the Flutter app:

    Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: NetworkImage('https://www.exampledomain.com/images/background.jpg'),
          fit: BoxFit.fill,
        ),
      ),
    

    )

    So, to apply background image in Container widget, we have to use decoration property. In the decoration property we supply a new BoxDecoration() object and this object should have an image property which points to the image resource URL. In the above snippet, image propery is instantiated a NetworkImage() object which is pointing to an image URL.

    0 讨论(0)
提交回复
热议问题