颤动依赖性flutter_svg自从升级到颤动v1.1.1以来未正确加载SVG图像。
我希望从this source中显示SVG图像,但是程序会自行暂停,并且图像永远不会加载到placeholderBuilder
之外
这是我用来产生此问题的代码:
new SvgPicture.network(
sparkString,
placeholderBuilder: (BuildContext context) => new Container(
decoration: new BoxDecoration(
color: const Color(0xFF3C4E57),
borderRadius: new BorderRadius.all(
const Radius.circular(5.0),
),
),
padding: const EdgeInsets.all(5.0),
alignment: Alignment.center,
child: CupertinoActivityIndicator(radius: 10.0)
),
fit: BoxFit.fill,
height: _height*0.14,
width: _width*0.30,
color: Colors.white.withAlpha(85),
),
这是出现的问题:
Flutter在svg_parser.dart
,parseSvgElement()
这是调试控制台中的输出
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following RangeError was thrown building Builder(dirty):
flutter: RangeError (index): Invalid value: Not in range 0..9, inclusive: 10
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 List.[] (dart:core/runtime/libgrowable_array.dart:145:60)
flutter: #1 _HomePageState._allWidget.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:gucci/home_page.dart:3362:73)
flutter: #2 Builder.build (package:flutter/src/widgets/basic.dart:5736:41)
flutter: #3 StatelessElement.build (package:flutter/src/widgets/framework.dart:3774:28)
flutter: #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
flutter: #5 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
flutter: #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #10 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #17 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #18 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #20 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #22 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #24 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #25 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #26 StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
flutter: #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #30 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
flutter: #31 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #32 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #33 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #34 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #35 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #36 SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1028:36)
flutter: #37 SliverMultiBoxAdaptorElement.performRebuild.processElement (package:flutter/src/widgets/sliver.dart:978:34)
flutter: #38 List.forEach (dart:core/runtime/libgrowable_array.dart:278:8)
flutter: #39 SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:989:36)
flutter: #40 SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:955:7)
flutter: #41 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #42 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4585:32)
flutter: #43 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
flutter: #44 _ViewportElement.update (package:flutter/src/widgets/viewport.dart:192:11)
flutter: #45 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #46 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #47 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #48 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
flutter: #49 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #50 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #51 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #52 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #53 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #54 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #55 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #56 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #57 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #58 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #59 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #60 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #61 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #62 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #63 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #64 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #65 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #66 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #67 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #68 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #69 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #70 StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
flutter: #71 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #73 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #74 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #75 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #76 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #77 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #78 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #79 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #80 StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
flutter: #81 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #82 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #83 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #84 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
flutter: #85 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
flutter: #86 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #87 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #88 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #89 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #90 _invoke (dart:ui/hooks.dart:159:13)
flutter: #91 _drawFrame (dart:ui/hooks.dart:148:3)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
答案 0 :(得分:2)
我玩过SVG,如果您删除标记,它会起作用。我怀疑flutter_svg库尚不支持marker-end
。它应该会抛出更好的错误,或者不会失败。
如果可以从应该解决问题的SVG中删除该标记和标记末端。如果那不是一个选择,则可以在库中open an issue上使用,也许他们可以添加它(或者您可以自己= D来完成)。
如果您提交了它,请使用它作为最小示例:
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
MyAppState createState() {
return new MyAppState();
}
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
height: 300,
width: 300,
color: Colors.blue,
child: SvgPicture.string(
'''
<?xml version="1.0" standalone="no"?>
<svg viewBox="-2 -4 100 20" width="100" height="20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker id="neatchart-markerCircle-1472608912" markerWidth="2" markerHeight="2" refX="1" refY="1" markerUnits="strokeWidth">
<circle class="neatchart-marker" cx="1" cy="1" r="1" stroke="none" fill="#F00" />
</marker>
<linearGradient id="neatchart-fadeFromNothing-1472608912" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse">
<stop offset="0.5%" stop-color="#000" stop-opacity="0"></stop>
<stop offset="2%" stop-color="#000" stop-opacity="1"></stop>
<stop offset="100%" stop-color="#000" stop-opacity="1"></stop>
</linearGradient>
</defs>
<g class="neatchart">
<g class="chart__plotLine"
fill="none"
stroke-width="1.3333333333333"
stroke-linejoin="round"
stroke-linecap="round"
stroke="url(#neatchart-fadeFromNothing-1472608912)"
marker-end="url(#neatchart-markerCircle-1472608912)"
>
<path d="M0,0 1.85,2.02 3.69,2.25 5.54,1.53 7.38,4 9.23,4.22 11.08,4.81 12.92,6.77 14.77,6.11 16.62,4.89 18.46,5.11 20.31,5.02 22.15,6.18 24,6.39 25.85,6.53 27.69,7.33 29.54,7.52 31.38,6.87 33.23,6.06 35.08,5.9 36.92,5.7 38.77,6.28 40.62,6.84 42.46,7.17 44.31,7.02 46.15,7.64 48,7.72 49.85,8 51.69,7.96 53.54,7.82 55.38,7.44 57.23,6.76 59.08,6.88 60.92,7.66 62.77,7.98 64.62,7.82 66.46,7.56 68.31,7.5 70.15,7.89 72,7.91 73.85,7.78 75.69,7.76 77.54,7.75 79.38,7.7 81.23,7.81 83.08,7.91 84.92,7.83 86.77,8.23 88.62,9.01 90.46,9.51 92.31,9.64 94.15,9.96 96,10 " />
</g>
</g>
</svg>
''',
fit: BoxFit.contain,
),
),
),
),
);
}
}
这实际上是为我呈现的:
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
MyAppState createState() {
return new MyAppState();
}
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
height: 300,
width: 300,
color: Colors.blue,
child: SvgPicture.string(
'''
<?xml version="1.0" standalone="no"?>
<svg viewBox="-2 -4 100 20" width="100" height="20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="neatchart-fadeFromNothing-1472608912" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="userSpaceOnUse">
<stop offset="0.5%" stop-color="#000" stop-opacity="0"></stop>
<stop offset="2%" stop-color="#000" stop-opacity="1"></stop>
<stop offset="100%" stop-color="#000" stop-opacity="1"></stop>
</linearGradient>
</defs>
<g class="neatchart">
<g class="chart__plotLine"
fill="none"
stroke-width="1.3333333333333"
stroke-linejoin="round"
stroke-linecap="round"
stroke="url(#neatchart-fadeFromNothing-1472608912)"
>
<path d="M0,0 1.85,2.02 3.69,2.25 5.54,1.53 7.38,4 9.23,4.22 11.08,4.81 12.92,6.77 14.77,6.11 16.62,4.89 18.46,5.11 20.31,5.02 22.15,6.18 24,6.39 25.85,6.53 27.69,7.33 29.54,7.52 31.38,6.87 33.23,6.06 35.08,5.9 36.92,5.7 38.77,6.28 40.62,6.84 42.46,7.17 44.31,7.02 46.15,7.64 48,7.72 49.85,8 51.69,7.96 53.54,7.82 55.38,7.44 57.23,6.76 59.08,6.88 60.92,7.66 62.77,7.98 64.62,7.82 66.46,7.56 68.31,7.5 70.15,7.89 72,7.91 73.85,7.78 75.69,7.76 77.54,7.75 79.38,7.7 81.23,7.81 83.08,7.91 84.92,7.83 86.77,8.23 88.62,9.01 90.46,9.51 92.31,9.64 94.15,9.96 96,10 " />
</g>
</g>
</svg>
''',
fit: BoxFit.contain,
),
),
),
),
);
}
}