one_dollar_unistroke_recognizer 1.2.0 copy "one_dollar_unistroke_recognizer: ^1.2.0" to clipboard
one_dollar_unistroke_recognizer: ^1.2.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';

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: [
            Center(
              child: Card(
                color: Colors.blue.withOpacity(0.1),
                margin: const EdgeInsets.all(16),
                child: Padding(
                  padding: const EdgeInsets.all(8),
                  child: Wrap(
                    spacing: 8,
                    runSpacing: 8,
                    children: [
                      for (final referenceUnistroke in referenceUnistrokes)
                        Chip(
                          label: Text('${referenceUnistroke.name}'),
                        ),
                    ],
                  ),
                ),
              ),
            ),
            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);
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
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

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, vector_math

More

Packages that depend on one_dollar_unistroke_recognizer