show_touches 0.0.1

SDKflutter
Platformandroidioswindowslinuxmacosweb

Show finger touch effects for Flutter, with support for multiple fingers, controllers, custom widgets, and animations.

GitHub stars Pub.dev likes

📓 Language: English | 中文



Show Touches

stable package dev package pub points CodeFactor codecov top language

Show finger touch effects for Flutter!


preview1.gif

Table of contents 🪄


Features ✨

  • 👇 Multiple fingers (pointers)
  • 🔧 Controller control
  • ⚙️ Customizable pointer widgets and animations

Install 🎯

Versions compatibility 🐦

Flutter3.3.0+
show_touches 0.0.1+✅

Platforms compatibility 📱

AndroidiOSWebmacOSWindowsLinux
✅✅✅✅✅✅

Add package 📦

Run this command with Flutter,

$ flutter pub add show_touches

or add show_touches to pubspec.yaml dependencies manually.

dependencies:
  show_touches: ^latest_version

Simple usage 📖

Example: show_touches/example

ShowTouches 📦

ShowTouches widget will have default gesture logic and pointer widgets.

/// Import show_touches
import 'package:show_touches/show_touches.dart';

MaterialApp(
  builder: ShowTouches.init(),
  home: XxxPage(),
);

/// or

ShowTouches(child: XxxPage()),

Usage 📖

ShowTouches widget parameters 🤖

ParameterTypeDefaultDescription
child requiredWidget--
enablebooltruetrue (enable)
false (disable)
controllerShowTouchesController?nullShowTouchesController to control the pointer.
pointerBuilderPointerBuilder?nullCustom pointer widget, but it will cause the defaultPointerStyle to be invalid.
defaultPointerStyleDefaultPointerStyleDefaultPointerStyle()Default style for the pointer widget when pointerBuilder is not used.
showDurationDurationDuration(milliseconds: 50)Show animation duration (pointer).
removeDurationDurationDuration(milliseconds: 200)Remove animation duration (pointer).

PointerBuilder 📄

Example:


ShowTouches(
  pointerBuilder: (
    BuildContext context,
    int pointerId,
    Offset position,
    Animation<double> animation,
  ) {
    final Animation<double> scaleAnimation = Tween<double>(
      begin: 2.0,
      end: 1.0,
    ).animate(animation);

    return Positioned(
      left: position.dx - 30.0,
      top: position.dy - 30.0,
      child: IgnorePointer(
        ignoring: true,
        child: ScaleTransition(
          scale: scaleAnimation,
          child: FadeTransition(
            opacity: animation,
            child: Container(
              width: 60,
              height: 60,
              color: Colors.black,
            ),
          ),
        ),
      ),
    );
  },
  child: XxxPage(),
),

ParameterTypeDescription
contextBuildContext-
pointerIdintPointer (touch) ID.
positionOffsetCurrent touch position.
animationAnimation<double>Animation controller.

ShowTouchesController 📄

You can use the controller to control the pointers in the ShowTouches widget,
or you can implement your own gesture logic to control the pointers.

Example:


final ShowTouchesController controller = ShowTouchesController();

......

@override
void dispose() {
  controller.dispose();
  super.dispose();
}

......

Listener(
  onPointerDown: (event) => controller.addPointer(...),
  onPointerMove: (event) => controller.updatePointer(...),
  onPointerUp: (event) => controller.removePointer(...),
  onPointerCancel: (event) => controller.removePointer(...),
  behavior: HitTestBehavior.translucent,
  child: child,
);

Get all pointer data

controller.data to get all the pointer data (Map<int, PointerData>).

Map<int, PointerData> -> key: pointerId, value: PointerData

PointerData
ParameterTypeDescription
pointerIdintPointer (touch) ID.
positionStateValueNotifier<Offset>Current touch position.
animationControllerAnimationControllerAnimation controller.
pointerOverlayEntryOverlayEntry?Pointer OverlayEntry.

addPointer()

ParameterTypeDefaultDescription
context requiredBuildContext--
pointerId requiredint-Pointer (touch) ID.
position requiredOffset-Current touch position.
animationController requiredAnimationController-Animation controller.
pointerBuilderPointerBuilder?nullCustom pointer widget, but it will cause the defaultPointerStyle to be invalid.
defaultPointerStyleDefaultPointerStyleDefaultPointerStyle()Default style for the pointer widget when pointerBuilder is not used.

updatePointer()

ParameterTypeDefaultDescription
pointerId requiredint-Pointer (touch) ID.
position requiredOffset-Current touch position.

removePointer()

ParameterTypeDefaultDescription
pointerId requiredint-Pointer (touch) ID.

disposePointer()

ParameterTypeDefaultDescription
pointerId requiredint-Pointer (touch) ID.

Contributors ✨

AmosHuKe
AmosHuKe

License 📄

MIT License
Open sourced under the MIT license.

© AmosHuKe