one_dollar_unistroke_recognizer 1.3.0 copy "one_dollar_unistroke_recognizer: ^1.3.0" to clipboard
one_dollar_unistroke_recognizer: ^1.3.0 copied to clipboard

The $1 Unistroke Recognizer, a 2D single-stroke recognizer, plus features like straight line recognition, the Protractor enhancement, a way to correct user's shapes, and more.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:one_dollar_unistroke_recognizer/one_dollar_unistroke_recognizer.dart';
import 'package:one_dollar_unistroke_recognizer_example/canvas_draw.dart';
import 'package:one_dollar_unistroke_recognizer_example/unistroke_preview.dart';

final recognized = ValueNotifier<RecognizedUnistroke?>(null);
Timer? pointDebounce;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '\$1 Unistroke Recognizer Demo',
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: ValueListenableBuilder(
            valueListenable: recognized,
            builder: (context, recognized, child) {
              return Text(
                recognized == null
                    ? 'Draw below to detect a shape'
                    : 'Detected "${recognized.name}" with score '
                        '${recognized.score.toStringAsFixed(2)}',
              );
            },
          ),
        ),
        body: Column(
          children: [
            Wrap(
              spacing: 8,
              runSpacing: 8,
              children: [
                for (final shape in DefaultUnistrokeNames.values)
                  UnistrokePreview(
                    unistroke: referenceUnistrokes.firstWhere(
                      (unistroke) => unistroke.name == shape,
                    ),
                  ),
              ],
            ),
            Expanded(
              child: SizedBox(
                width: double.infinity,
                child: CanvasDraw(
                  recognized: recognized,
                  onDraw: (points) {
                    if (pointDebounce == null || !pointDebounce!.isActive) {
                      pointDebounce =
                          Timer(const Duration(milliseconds: 100), () {
                        recognized.value = recognizeUnistroke(points);
                      });
                    }
                  },
                  onDrawEnd: (points) {
                    pointDebounce?.cancel();
                    pointDebounce = null;
                    recognized.value = recognizeUnistroke(points);
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
0
pub points
84%
popularity

Publisher

verified publisheradil.hanney.org

The $1 Unistroke Recognizer, a 2D single-stroke recognizer, plus features like straight line recognition, the Protractor enhancement, a way to correct user's shapes, and more.

Homepage
Repository (GitHub)
View/report issues

Topics

#one-dollar #unistrokes #shape-recognition #gesture-recognition

License

unknown (license)

Dependencies

flutter, vector_math

More

Packages that depend on one_dollar_unistroke_recognizer