Search code examples
cssfluttersvgbackgroundcontainers

how to set svg picture as background of container in flutter?


I cannot figure out how to set background image of container using svg picture ! I tried setting image as background but it didnt work that method works with asset images or online images but is not successfully working with svg pictures i am using svg.picture . I am noobie !


Solution

  • You can use the flutter_svg package to display the svg image.

    Instead of using it as background image, i suggest you to use Stack to stack the svg image in the back and your widget in the front.

    Example

    Widget build(BuildContext context) {
      return Scaffold(
        body: Stack(
          children: <Widget>[
            SvgPicture.asset(
              'assets/background.svg',
              alignment: Alignment.center,
              width: 200,
              height: 200,
            ),
            Container(
              child:  << Your Widget >>,
            ),
          ],
        ),
      );
    }