flutter_kanji_view 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

flutter_kanji_view Pub #

A Flutter library to draw kanji character with animation.

Introduction #

This library is based on biocarl's drawing_animation, but with some modifications to display kanji SVG from KanjiVG.

Moreover, it exposes a third constructor: .str, to display the kanji SVG data downloaded as a string (very handy if you store those SVG on your server).

1. Add dependency into your ppubspec.yaml #

dependencies:
  flutter_kanji_view: ^1.0.0
  • Download KanjiVG pack from here , get the zip file.

  • Add the path into yml:

assets:
  - assets/0ff10.svg

3. Use the widget: Same with drawing_animation, you can use it in two ways: #

  • Without controller: The animation will run once:
KanjiViewer.svg(
  "assets/0ff10.svg",
  run: this.run,
  duration: new Duration(seconds: 3),
)
  • With controller: You will have more control over the widget.
class Playground extends StatefulWidget {
  @override
  _PlaygroundState createState() {
    return _PlaygroundState();
  }
}

class _PlaygroundState extends State<Playground>
    with SingleTickerProviderStateMixin {
  var run = true;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 3));
  }

  @override
  Widget build(BuildContext context) {
    var char = getKanjiUnicode('雨');

    return Scaffold(
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Container(
            width: 400,
            height: 400,
            alignment: Alignment.center,
            padding: const EdgeInsets.all(6),
            color: Colors.black12,
            child: KanjiViewer.svg("assets/vectors/" + char + ".svg",
                scaleToViewport: true,
                duration: new Duration(seconds: 6)),
          ),
          RaisedButton(
              child: Text('Redraw'),
              onPressed: () {
                _controller.reset();
                _controller.forward();
              })
        ],
      ),
    );
  }
}

4. Advanced usage: #

There are 3 mores for drawing SVG, mostly from the source they were from.

*** From SVG asset ***: This might be the most common use.

KanjiViewer.svg("<SVG Path>")

*** From SVG string ***

This can be convenient when you store your SVG data somewhere on the remote server, and retrieve via API:

KanjiViewer.str("<SVG string data>")

*** From Path data ***

// Of the List<Path>
KanjiViewer.paths(pathList)

You can use some methods in SVGHelper class (such as getCoordinatesGroup and buildPath) for Path parsing. I'm not going to document it any time soon because of lacking time though.

TODO:

Since the core library borrows a lot from drawing_animation, their TODOs are also considered this lib's TODOs. This lib, however, add some more priority tasks that I can foresee:

  • Expose Paint object so users can customize the stroke color / width.
  • Expose a colorSeed array for distinct strokes. It should be a List of Color object.

[1.0.2] - TODO: Add release date. #

  • Bump version, minor fix.

[1.0.1] - TODO: Add release date. #

  • Bump version, added minor example.

[1.0.0] - TODO: Add release date. #

  • Initial release.

example/example.dart

class Playground extends StatefulWidget {
  @override
  _PlaygroundState createState() {
    return _PlaygroundState();
  }
}

class _PlaygroundState extends State<Playground>
    with SingleTickerProviderStateMixin {
  var run = true;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 3));
  }

  @override
  Widget build(BuildContext context) {
    var char = getKanjiUnicode('雨');

    return Scaffold(
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Container(
            width: 400,
            height: 400,
            alignment: Alignment.center,
            padding: const EdgeInsets.all(6),
            color: Colors.black12,
            child: KanjiViewer.svg("assets/vectors/" + char + ".svg",
                scaleToViewport: true,
                duration: new Duration(seconds: 6)),
          ),
          RaisedButton(
              child: Text('Redraw'),
              onPressed: () {
                _controller.reset();
                _controller.forward();
              })
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_kanji_view: ^1.0.2

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:flutter_kanji_view/flutter_kanji_view.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flutter_kanji_view that is a package requiring null.

Package not compatible with runtime flutter-web on web

Because:

  • package:flutter_kanji_view/flutter_kanji_view.dart that imports:
  • package:flutter_kanji_view/fklib/drawing_widget.dart that imports:
  • package:flutter_kanji_view/fklib/drawing_state_with_ticker.dart that imports:
  • package:flutter_kanji_view/fklib/abstract_drawing_state.dart that imports:
  • package:flutter_kanji_view/fklib/path_painter_builder.dart that imports:
  • package:flutter_kanji_view/fklib/painter.dart that imports:
  • dart:io

Health suggestions

Fix lib/fklib/range.dart. (-0.50 points)

Analysis of lib/fklib/range.dart reported 1 hint:

line 16 col 17: Override hashCode if overriding ==.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path_parsing ^0.1.3 0.1.4
xml ^3.2.5 3.7.0 4.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
meta 1.1.8 1.2.1
petitparser 3.0.4
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test
mockito ^4.0.0
test ^1.5.1