Google's ML Kit Digital Ink Recognition for Flutter

Pub Version analysis Star on Github License: MIT

A Flutter plugin to use Google's ML Kit Digital Ink Recognition to recognize handwritten text on a digital surface in hundreds of languages, as well as classify sketches.

Getting Started

Before you get started read about the requirements and known issues of this plugin here.


Digital Ink Recognition

Create an instance of DigitalInkRecognizer

String languageCode; // BCP-47 Code from
final digitalInkRecognizer = DigitalInkRecognizer(languageCode: languageCode);

Process ink

final p1 = StrokePoint(x: x1, y: y1, t:; // make sure that `t` is a long
final p2 = StrokePoint(x: x1, y: y1, t:; // make sure that `t` is a long

Stroke stroke1 = Stroke(); // it contains all of the StrokePoint
stroke1.point = [p1, p2, ...]

Ink ink = Ink(); // it contains all of the Stroke
ink.strokes = [stroke1, stroke2, ...];

final List<RecognitionCandidate> candidates = await digitalInkRecognizer.recognize(ink);

for (final candidate in candidates) {
  final text = candidate.text;
  final score = candidate.score;

Make sure you download the language model before processing any Ink.

To improve the accuracy of text recognition you can set an writing area and pre-context. More details here.

String preContext;
double width;
double height;
final context = DigitalInkRecognitionContext(
  preContext: preContext,
  writingArea: WritingArea(width: width, height: height),

final List<RecognitionCandidate> candidates = await digitalInkRecognizer.recognize(ink, context: context);

Release resources with close()


Managing remote models

Create an instance of model manager

final modelManager = DigitalInkRecognizerModelManager();

Check if model is downloaded

final bool response = await modelManager.isModelDownloaded(model);

Download model

final bool response = await modelManager.downloadModel(model);

Delete model

final bool response = await modelManager.deleteModel(model);

Example app

Find the example app here.


Contributions are welcome. In case of any problems look at existing issues, if you cannot find anything related to your problem then open an issue. Create an issue before opening a pull request for non trivial fixes. In case of trivial fixes open a pull request directly.