Skip to content

Is it possible to import simple svg that has just one path? #10

Open

Description

@atreeon

Thanks for the package, it looks great! I have a couple of existing svgs that are super simple, just one path. How do I convert that to the json and import it, is that possible?

Activity

  1. KevinVan720 commented on Feb 16, 2023

    @KevinVan720
    Owner

    Hi. This package is purposed for creating border shapes (must be a closed path). If your path is simple enough, you can try to recreate it here: https://fluttershape.com/ (in Bezier mode) and export it as JSON. Sorry I didn't implement an svg import feature.

  2. atreeon commented on Feb 16, 2023

    @atreeon
    Author
  3. atreeon commented on Feb 16, 2023

    @atreeon
    Author

    actually this works in converting the list of svg co-ordinates (I previously misunderstood how the svg worked). I could add it somewhere as a pull request if you think it might be cool.

    Offset _getXY(String coOrdinates) {
      var split = coOrdinates.split(",");
      return Offset(double.parse(split[0]), double.parse(split[1]));
    }
    
    Map<String, dynamic> morphableConvertCoOrdinates(String coOrdinates) {
      var nodes = coOrdinates.split("\n").where((element) => element.length > 10).toList();
    
      var result = nodes.map(
        (e) {
          var nodeLine = e.trim();
          var positions = nodeLine.split(" ");
    
          return {
            "prev": {"dx": _getXY(positions[0]).dx, "dy": _getXY(positions[0]).dy},
            "pos": {"dx": _getXY(positions[1]).dx, "dy": _getXY(positions[1]).dy},
            "next": {"dx": _getXY(positions[2]).dx, "dy": _getXY(positions[2]).dy},
          };
        },
      ).toList();
    
      var json = {
        "type": "Path",
        "border": {"color": "ff000000", "width": 0, "style": "none", "strokeCap": "butt", "strokeJoin": "miter"},
        "path": {
          "size": {"width": 600, "height": 600},
          "nodes": result
        },
      };
    
      return json;
    }
    
  4. atreeon commented on Feb 16, 2023

    @atreeon
    Author

    btw, I really like it! I think if you update your examples you should do something like this.

    Morph2.mov
  5. pbouttier commented on Feb 20, 2023

    @pbouttier

    @atreeon could you provide a full example ? How about the performance ?

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions