I am developing an application with Flutter that involves render, and then interacting with, an svg-encoded piece of sheet music. Specifically, I need to be able to draw and re-draw quickly, and get the id attribute of whatever element is under any mouse events. Doing this in a Javascript environment (not in Flutter) is quite easy and just requires adding in the svg to a , and attaching a mouse listener.
The specific problem that I am running into in Flutter is that none of the svg libraries support the kinds of features that this sheet music encoding scheme uses (nested tag, tag, , , overflow attributes, etc). So my question is, what can I do to get this kind of svg rendering? And does that still allow for determining the element that is under a mouse event?
I imagine that converting the svg to an image (png, jpeg, etc) is too slow, and that would require re-rendering the image to a different resolution when the user scrolls. What options exist? Is there a way to define a different drawing solution for each platform I want to use? I hope to port my application to Desktop (primary platform), Web (in a limited capacity), and perhaps Mobile.
I have tried the following libraries in flutter’s pub dev:
flutter_svg
jovial_svg
Neither of them were able to render any kind of image from my svg file. Though I got both to work with a simple svg file (an example dart icon)
Thanks for any suggestions and help!
More information:
My system: Windows 64
Flutter 3.16.9
Dart 3.2.6
Engine: revision 41456452f2
(Svg files being rendered dynamically by the c++ open-source library Verovio)
Example of the syntax of the svg file itself: (abridged from it’s original 760-line file)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="630px" height="891px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mei="http://www.music-encoding.org/ns/mei" overflow="visible">
<desc>Engraved by Verovio 4.2.0-dev[undefined]</desc>
<defs>
<symbol id="E242-1chrny2" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M206 -748c32 48 49 100 49 149c0 89 -55 168 -168 203c-18 5 -47 9 -87 16v190v190h22c8 0 33 -61 71 -95c4 -3 -2 3 61 -56c62 -58 122 -137 122 -241c0 -32 -7 -65 -17 -96c11 -29 17 -60 17 -94c0 -71 -32 -148 -67 -190c-6 -5 -10 -7 -13 -7s-5 2 -5 5l4 10 c1 3 6 8 11 16zM248 -463c4 18 7 38 7 57c0 105 -80 173 -168 200c-11 3 -27 6 -47 9c9 -17 23 -61 53 -88c4 -3 -2 3 61 -56c36 -33 71 -74 94 -122z" />
</symbol>
<symbol id="E050-1chrny2" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M441 -245c-23 -4 -48 -6 -76 -6c-59 0 -102 7 -130 20c-88 42 -150 93 -187 154c-26 44 -43 103 -48 176c0 6 -1 13 -1 19c0 54 15 111 45 170c29 57 65 106 110 148s96 85 153 127c-3 16 -8 46 -13 92c-4 43 -5 73 -5 89c0 117 16 172 69 257c34 54 64 82 89 82 c21 0 43 -30 69 -92s39 -115 41 -159v-15c0 -109 -21 -162 -67 -241c-13 -20 -63 -90 -98 -118c-13 -9 -25 -19 -37 -29l31 -181c8 1 18 2 28 2c58 0 102 -12 133 -35c59 -43 92 -104 98 -184c1 -7 1 -15 1 -22c0 -123 -87 -209 -181 -248c8 -57 17 -110 25 -162 c5 -31 6 -58 6 -80c0 -30 -5 -53 -14 -70c-35 -64 -88 -99 -158 -103c-5 0 -11 -1 -16 -1c-37 0 -72 10 -108 27c-50 24 -77 59 -80 105v11c0 29 7 55 20 76c18 28 45 42 79 44h6c49 0 93 -42 97 -87v-9c0 -51 -34 -86 -105 -106c17 -24 51 -36 102 -36c62 0 116 43 140 85 c9 16 13 41 13 74c0 20 -1 42 -5 67c-8 53 -18 106 -26 159zM461 939c-95 0 -135 -175 -135 -286c0 -24 2 -48 5 -71c50 39 92 82 127 128c40 53 60 100 60 140v8c-4 53 -22 81 -55 81h-2zM406 119l54 -326c73 25 110 78 110 161c0 7 0 15 -1 23c-7 95 -57 142 -151 142h-12 zM382 117c-72 -2 -128 -47 -128 -120v-7c2 -46 43 -99 75 -115c-3 -2 -7 -5 -10 -10c-70 33 -116 88 -123 172v11c0 68 44 126 88 159c23 17 49 29 78 36l-29 170c-21 -13 -52 -37 -92 -73c-50 -44 -86 -84 -109 -119c-45 -69 -67 -130 -67 -182v-13c5 -68 35 -127 93 -176 s125 -73 203 -73c25 0 50 3 75 9c-19 111 -36 221 -54 331z" />
</symbol>
</defs>
<style type="text/css">g.page-margin{font-family:Times,serif;} g.ending, g.fing, g.reh, g.tempo{font-weight:bold;} g.dir, g.dynam, g.mNum{font-style:italic;} g.label{font-weight:normal;}</style>
<svg class="definition-scale" color="black" viewBox="0 0 21000 29700">
<g class="page-margin" transform="translate(500, 500)">
<g id="myw3f4h" class="mdiv pageMilestone" />
<g id="si7b7ih" class="score pageMilestone" />
<g id="schrbg5" class="system">
<path d="M1523 1395 L1523 4072" stroke="currentColor" stroke-width="27" />
<g id="gkn1966" class="grpSym">
<path d="M1438,4054 C1078,3514 1528,2914 1258,2734 C1591,2914 1141,3514 1438,4054" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="18" />
<path d="M1438,1413 C1141,1953 1591,2554 1258,2734 C1528,2554 1078,1953 1438,1413" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="18" />
</g>
<g id="l1lnivk3" class="label">
<text x="1105" y="2824" text-anchor="end" font-size="0px">
<tspan id="t5bi2fu" class="text">
<tspan font-size="405px">Piano</tspan>
</tspan>
</text>
</g>
<g id="spkgdb0" class="section systemMilestone" />
<g id="d1e104" class="measure">
<g id="ssrt8ln" class="staff">
<path d="M1510 3352 L5744 3352" stroke="currentColor" stroke-width="13" />
<path d="M1510 3532 L5744 3532" stroke="currentColor" stroke-width="13" />
<path d="M1510 3712 L5744 3712" stroke="currentColor" stroke-width="13" />
<path d="M1510 3892 L5744 3892" stroke="currentColor" stroke-width="13" />
<path d="M1510 4072 L5744 4072" stroke="currentColor" stroke-width="13" />
<g id="c1yswqtr" class="clef">
<use xlink:href="#E062-1chrny2" x="1627" y="3532" height="720px" width="720px" />
</g>
<g id="kf5ls9m" class="keySig">
<g id="kzwb8ht" class="keyAccid">
<use xlink:href="#E260-1chrny2" x="2308" y="3892" height="720px" width="720px" />
</g>
</g>
<g id="m1xwh8sv" class="meterSig">
<use xlink:href="#E082-1chrny2" x="2616" y="3532" height="720px" width="720px" />
<use xlink:href="#E084-1chrny2" x="2621" y="3892" height="720px" width="720px" />
</g>
<g id="l1d0tlud" class="layer">
<g id="sjlp4ru" class="space" />
</g>
</g>
<g id="d1x1taea" class="dir">
<text x="3189" y="276" font-size="0px">
<tspan id="rk2beft" class="rend">
<tspan id="t1x5g3fw" class="text">
<tspan font-size="405px">Not fast.</tspan>
</tspan>
</tspan>
</text>
</g>
<g id="t5anxs" class="tie">
<path d="M4250,1260 C4315,1107 4500,1107 4566,1260 C4473,1154 4342,1154 4250,1260" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="9" />
</g>
<g id="t1xucvsx" class="tie">
<path d="M4250,2160 C4342,2267 4473,2267 4566,2160 C4500,2314 4315,2314 4250,2160" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="9" />
</g>
<g id="b11owwib" class="barLine">
<path d="M5731 1395 L5731 2115" stroke="currentColor" stroke-width="27" />
<path d="M5731 3352 L5731 4072" stroke="currentColor" stroke-width="27" />
</g>
</g>
...