arrow_path 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

arrow_path #

Draw arrows with Path objects easily. Paths can be composited to add arrows to any curve and draw all at once.

The arrow is drawn using the direction of the tangent to the curve at the end of the curve. It features an adjustment parameter to also look at the tangent just before the end of the segment and rotate the tip of the arrow based on the angle difference to improve the look of the arrow when the curvature at the end high.

Getting Started #

Have a look at the example app to get started.

1.0.0 - 2019-05-11 #

  • Initial release.

example/lib/main.dart

import 'dart:ui';

import 'package:arrow_path/arrow_path.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Arrow Path Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: ExampleApp(),
    );
  }
}

class ExampleApp extends StatefulWidget {
  ExampleApp({Key key}) : super(key: key);

  @override
  _ExampleAppState createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  @override
  void initState() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Arrow Path Example')),
      body: Container(
        constraints: BoxConstraints.expand(),
        child: CustomPaint(
          painter: ArrowPainter(),
        ),
      ),
    );
  }
}

class ArrowPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    TextSpan textSpan;
    TextPainter textPainter;
    Path path;

    // The arrows usually looks better with rounded caps.
    Paint paint = Paint()
      ..color = Colors.black
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeJoin = StrokeJoin.round
      ..strokeWidth = 3.0;

    /// Draw a single arrow.
    path = Path();
    path.moveTo(size.width * 0.25, size.height * 0.10);
    path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 0);
    path = ArrowPath.make(path: path);
    canvas.drawPath(path, paint..color = Colors.blue);

    textSpan = TextSpan(
      text: 'Single arrow',
      style: TextStyle(color: Colors.blue),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(minWidth: size.width);
    textPainter.paint(canvas, Offset(0, size.height * 0.06));

    /// Draw a double sided arrow.
    path = Path();
    path.moveTo(size.width * 0.25, size.height * 0.2);
    path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 0);
    path = ArrowPath.make(path: path, isDoubleSided: true);
    canvas.drawPath(path, paint..color = Colors.cyan);

    textSpan = TextSpan(
      text: 'Double sided arrow',
      style: TextStyle(color: Colors.cyan),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(minWidth: size.width);
    textPainter.paint(canvas, Offset(0, size.height * 0.16));

    /// Use complex path.
    path = Path();
    path.moveTo(size.width * 0.25, size.height * 0.3);
    path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 50);
    path.relativeCubicTo(0, 0, -size.width * 0.25, 0, -size.width * 0.5, 50);
    path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
    path = ArrowPath.make(path: path, isDoubleSided: true);
    canvas.drawPath(path, paint..color = Colors.blue);

    textSpan = TextSpan(
      text: 'Complex path',
      style: TextStyle(color: Colors.blue),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(minWidth: size.width);
    textPainter.paint(canvas, Offset(0, size.height * 0.28));

    /// Draw several arrows on the same path.
    path = Path();
    path.moveTo(size.width * 0.25, size.height * 0.53);
    path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 50);
    path = ArrowPath.make(path: path);
    path.relativeCubicTo(0, 0, -size.width * 0.25, 0, -size.width * 0.5, 50);
    path = ArrowPath.make(path: path);
    Path subPath = Path();
    subPath.moveTo(size.width * 0.375, size.height * 0.53 + 100);
    subPath.relativeCubicTo(
        0, 0, size.width * 0.125, 10, size.width * 0.25, -10);
    subPath = ArrowPath.make(path: subPath, isDoubleSided: true);
    path.addPath(subPath, Offset.zero);
    canvas.drawPath(path, paint..color = Colors.cyan);

    textSpan = TextSpan(
      text: 'Several arrows on the same path',
      style: TextStyle(color: Colors.cyan),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout(minWidth: size.width);
    textPainter.paint(canvas, Offset(0, size.height * 0.49));

    /// Adjusted
    path = Path();
    path.moveTo(size.width * 0.1, size.height * 0.8);
    path.relativeCubicTo(0, 0, size.width * 0.3, 50, size.width * 0.25, 75);
    path = ArrowPath.make(path: path, isAdjusted: true);
    canvas.drawPath(path, paint..color = Colors.blue);

    textSpan = TextSpan(
      text: 'Adjusted',
      style: TextStyle(color: Colors.blue),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.left,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout();
    textPainter.paint(canvas, Offset(size.width * 0.2, size.height * 0.77));

    /// Non adjusted.
    path = Path();
    path.moveTo(size.width * 0.6, size.height * 0.8);
    path.relativeCubicTo(0, 0, size.width * 0.3, 50, size.width * 0.25, 75);
    path = ArrowPath.make(path: path, isAdjusted: false);
    canvas.drawPath(path, paint..color = Colors.blue);

    textSpan = TextSpan(
      text: 'Non adjusted',
      style: TextStyle(color: Colors.blue),
    );
    textPainter = TextPainter(
      text: textSpan,
      textAlign: TextAlign.left,
      textDirection: TextDirection.ltr,
    );
    textPainter.layout();
    textPainter.paint(canvas, Offset(size.width * 0.65, size.height * 0.77));
  }

  @override
  bool shouldRepaint(ArrowPainter oldDelegate) => true;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  arrow_path: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:arrow_path/arrow_path.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
86
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package not compatible with SDK dart

because of import path [arrow_path]

Maintenance suggestions

Package is getting outdated. (-14.25 points)

The package was last published 59 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test