Dart 使用SVG作为容器的背景图像

Dart 使用SVG作为容器的背景图像,dart,flutter,Dart,Flutter,我正在使用flatter的SVG包(flatter\u SVG)渲染一个 我想使用SVG作为容器背景,在中间使用文本< /代码>。< /P> 这是我目前掌握的代码: Container( decoration: BoxDecoration( image: DecorationImage(image: SvgPicture.asset( 'assets/example.svg', ),), ),

我正在使用flatter的SVG包(
flatter\u SVG
)渲染一个

我想使用SVG作为<代码>容器背景,在中间使用<代码>文本< /代码>。< /P>

这是我目前掌握的代码:

Container(
      decoration: BoxDecoration(
          image: DecorationImage(image: SvgPicture.asset(
            'assets/example.svg',
          ),),
      ),
      children: <Widget>[
        Text('Welcome to my Flutter App',
          style: Theme.of(context).textTheme.display1.copyWith(
            color: Colors.white,
            fontWeight: FontWeight.bold
          )
        ),
      ],
    )
容器(
装饰:盒子装饰(
图像:装饰图像(图像:SvgPicture.asset(
“assets/example.svg”,
),),
),
儿童:[
文本(“欢迎使用我的颤振应用程序”,
样式:Theme.of(context).textTheme.display1.copyWith(
颜色:颜色,白色,
fontWeight:fontWeight.bold
)
),
],
)
我发现的问题是
SvgPicture
不是
ImageProvider
,因此我无法添加
BoxDecoration
以获得背景图像


有没有一种方法可以使用
SvgPicture
作为容器的盒子装饰或背景?

如何使用堆栈()并在其上构建所有内容。这就是我用一个图像作为整个视口的背景所做的

使用SVG图片的确切方法如下:

Widget build(BuildContext context) {

  return Scaffold(
    body: Stack(
      children: <Widget>[
        SvgPicture.asset(
          'assets/images/splash/background.svg',
          alignment: Alignment.center,
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
        )
        Container(
          child: Column(
            children: <Widget>[Expanded(child: _createLogo())],
          ),
        ),
      ],
    ),
  );
}
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
儿童:[
SvgPicture.asset(
“assets/images/splash/background.svg”,
对齐:对齐.center,
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
)
容器(
子:列(
子项:[已展开(子项:_createLogo())],
),
),
],
),
);
}
您也可以使用

像这样:

import 'package:flutter_svg_provider/flutter_svg_provider.dart';

Container(
      decoration: BoxDecoration(
          image: DecorationImage(image: Svg(
            'assets/example.svg',
          ),),
      ),
    )

如何使用堆栈布局实现这一点?找不到按照这篇文章所说的去做的方法。不起作用!!无法将参数类型“Svg”分配给参数类型“ImageProvider”。