dart - 使用 SVG 作为容器的背景图像
问题描述
从这个问题中,我使用 Flutter 的 SVG 包 ( flutter_svg
) 来渲染SVG 图像。
我想使用 SVG 作为中间的Container
背景Text
。
这是我到目前为止的代码:
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
不是,ImageProvider
所以我不能添加BoxDecoration
来获取背景图像。
有没有办法然后SvgPicture
用作容器的盒子装饰或背景?
解决方案
使用 SvgPicture 的确切方法是这样的:
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())],
),
),
],
),
);
}
推荐阅读
- kubernetes - Kubernetes Pods - 从主机节点注入环境变量
- javascript - 在插入新用户之前尝试检查我的 mongodb 中是否存在用户(以防止多个相同的电子邮件注册)
- mysql - 如何使用“WHERE NOT IN(...超过 1000 个项目...)”优化更新 SQL 查询?
- php - Docker + PHP + RabbitMQ
- ios - 为 iOS 平台构建的问题
- bash - 如何停止处理文件并继续处理管道中的下一个文件?
- java - 为什么我会收到此错误= [行:33] 错误:无法从类型 Reverse1 对非静态方法 reverse() 进行静态引用
- docusignapi - 与 DocuSign 中的所有签名者共享的自定义选项卡
- google-apps-script - 将工作表复制为新电子表格的脚本无法正常工作
- c# - 将 ID 分配给 ViewBag 并在 MVC 中为其赋值