Search packages, repositories and app categories

path_morph cover
Package detailsv1.1.1

path_morph

This package lets you create path tween animations. In other words, it lets you morph one path into another.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
98
Likes
61
Pub points
150

Install package

flutter pub add path_morph

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

path_morph is a Flutter package that enables smooth path tween animations, allowing developers to morph one custom path into another. It's ideal for creating fluid visual transitions between shapes or outlines in animations. The package supports all major platforms and integrates seamlessly with Flutter’s animation system. It works by interpolating the points of two paths over time, producing visually appealing results for UI elements like icons, loaders, or dynamic illustrations.

Use cases

  • Creating animated icon transitions
  • Designing fluid shape morphs in UI
  • Animating custom path-based graphics
  • Building interactive loading indicators
  • Enhancing visual storytelling in apps

Key features

  • Smooth path interpolation
  • Cross-platform support
  • Simple API for path animations
  • Integration with Flutter's AnimationController
  • Supports complex path geometries

Suitable for

  • UI/UX designers seeking dynamic visuals
  • Developers building animated illustrations
  • Apps requiring custom path transitions
  • Interactive prototypes with fluid motion

Considerations

  • Performance may vary with highly complex paths
  • Requires careful path structuring for smooth results
  • Best suited for lightweight animations
  • Not ideal for real-time user-drawn paths
  • Limited to static path morphs without external input

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Path Morph

This is a pure Dart package that lets you smoothly morph one Flutter Path object into another. You can think of this as a path tween animation. The idea is to take two paths, a source path and a destination path, and smoothly move the points of the source path until it looks exactly like the destination path.

Usage

First you need to sample two paths using the PathMorph.samplePaths() method, which returns a SampledPathData object.

SampledPathData data = PathMorph.samplePaths(path1, path2);

Then you call the PathMorph.generateAnimations() method to create an animation for every point in the path. This method needs an AnimationController object and a SampledPathData object as arguments. Additionally, it expects you to pass a function to it, one that takes two arguments itself. In the body of the function, you must call setState() and update the value of the shiftedPoints list, which is present in the SampledPathData object.

AnimationController controller = AnimationController(vsync: this,
                                    duration: Duration(seconds: 1));

PathMorph.generateAnimations(controller, data, (i,z) {
    setState((){
      data.shiftedPoints[i] = z;
    });
});

Lastly, while rendering the morph animation, you can call the PathMorph.generatePath() method and pass the shiftedPoints list to it. This returns a Path object you can draw on your canvas. If you are using a CustomPainter object, you'll want to pass the path as an argument to it.

@override
Widget build(BuildContext context) {
    return CustomPaint(painter: MyPainter(PathMorph.generatePath(data)));
}

Do take a look at the example project to get a better idea.

Important

This package currently allows you to morph two paths only if they both have an equal number of contours. You can think of a contour as a line you can draw without lifting the pen. For example, the path to draw a triangle, a circle, or a square has one contour only. But a path to draw two concentric circles will have two contours.

Categories

Source repository

Projects using this package

No data available yet.