【发布时间】:2019-03-19 12:39:28
【问题描述】:
我正在尝试将 svg 字符串中的图像显示到屏幕上。
我正在使用:https://pub.dartlang.org/packages/flutter_svg 来支持 svg。
final String svgAsString = '''<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="109" height="109" viewBox="0
0 109 109">
<g id="kvg:StrokePaths_080a1" style="fill:none;stroke:#000000;stroke-
width:3;stroke-linecap:round;stroke-linejoin:round;">
<path id="kvg:080a1-s1"
d="M20.22,18.74c0.77,0.77,0.79,2.14,0.8,3.05C21.38,62,20.62,75,11.5,89.39"/>
</g>
</svg>''';
我无法将此渲染到图像小部件或绘制到画布上。两种方法我都试过了,都没有成功。
我将在下面粘贴完整代码:我不确定我是否在正确的轨道上。
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class KanjiGradeGenerator extends StatefulWidget {
@override
_KanjiGradeState createState() => _KanjiGradeState();
}
class _KanjiGradeState extends State<KanjiGradeGenerator> {
_KanjiGradeState() {}
displaySVG() async {
<g id="kvg:StrokePaths_080a1" style="fill:none;stroke:#000000;stroke-
width:3;stroke-linecap:round;stroke-linejoin:round;">
<path id="kvg:080a1-s1"
d="M20.22,18.74c0.77,0.77,0.79,2.14,0.8,3.05C21.38,62,20.62,75,11.5,89.39"/>
</g>
</svg>''';
final DrawableRoot svgRoot = await svg.fromSvgString(rawSvg, rawSvg);
final Picture picture = svgRoot.toPicture();
PictureRecorder picRec;
Canvas can = Canvas(picRec);
setState(() {
can.drawPicture(picture);
});
}
Widget build(BuildContext context) {
return new Scaffold(
body: Container(
child: displaySVG()
),
);
}
}
我收到的错误是:
I/flutter (7791):“未来”类型不是“小部件”类型的子类型
【问题讨论】: