GithubHelp home page GithubHelp logo

folksable / shake_detector Goto Github PK

View Code? Open in Web Editor NEW
5.0 0.0 1.0 72 KB

a package to detect shake gestures for flutter, configurable and simple api.

Home Page: https://pub.dev/packages/shake_detector

License: MIT License

Kotlin 1.18% Ruby 13.91% Swift 6.78% Objective-C 0.37% Dart 77.75%
sensors shake-detection

shake_detector's Introduction

shake_detector

A flutter package to detect phone shakes, with pause and resume listening when the app is in background and foreground respectively.

Usage

1. Use as Widget

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('ShakeGesture Example')),
      body: Center(
        // The start.
        child: ShakeDetectWrap(
          enabled: true,
          onShake: () {
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Shake!')),
            );
          },
          child: const Center(
            child: OutlinedButton(
              onPressed: ShakeGestureTestHelperExtension.simulateShake,
              child: Text('Simulate Shake'),
            ),
          ),
        ),
		// The end.
      ),
    );
  }
}

2. Use as Listener

To listen to phone shake:

ShakeDetector detector = ShakeDetector.autoStart(
    onShake: () {
        // Do stuff on phone shake
    }
);

OR

This will wait for user to call startListening() to start listening to phone shake:

ShakeDetector detector = ShakeDetector.waitForStart(
    onShake: () {
        // Do stuff on phone shake
    }
);

// start listening later on, after using waitForStart constructor
detector.startListening();

Control Detector:

// usually you don't start listening but used in constructor
detector.startListening();

// pause shake listening for a while (e.g. when app is in background)
detector.pauseListening();

// resume shake listening after pause
detector.resumeListening();

// stop shake detection
// this will cancel the stream subscription 
detector.stopListening();

shake_detector's People

Contributors

dhikshith12 avatar

Stargazers

HeavenOSK avatar TUSHAR BHAMBERE avatar Alberto Caro avatar Mohammad El Shaari avatar  avatar

Forkers

ah-sabbir

shake_detector's Issues

Error: 'onPhoneShake' is not defined.

Error: 'onPhoneShake' is not defined; 'onShake' is used instead.

Please update the documentation to reflect this change. Additionally, if possible, update the example documentation on pub.dev to reflect the usage of 'onShake' instead of 'onPhoneShake'.

Thank in advance.

Pause Listening to Shake while App in Background.

currently the package is still listening to shakes happening when the app is not currently visible but in memory.

need to add pause method to the controller to fix this and listen to lifecycle changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.