Code Monkey home page Code Monkey logo

shake's Introduction

shake

A flutter package to detect phone shakes.

To listen to phone shake:

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

OR

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

detector.startListening();

To stop listening:

detector.stopListening();

shake's People

Contributors

deven98 avatar guykogus avatar jonaswanke avatar maxlapides avatar mohamedfboussaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shake's Issues

Shake does not work on Safari in iPhone.

I am developing an application using your library. I run my application on iPhone Safari and shake it, but Safari only shows "undo typing". How can I catch event shake in Safari? Thanks in advance.

Really inconsistent between Android & iOS

I have two test devices:

  • Pixel 4 XL
  • iPhone SE 3rd gen

Same settings:

    minimumShakeCount: 3,
    shakeCountResetTime: 2000,
    shakeSlopTimeMS: 250,
    shakeThresholdGravity: 1.3,

On the Pixel, I need to shake really hard, on the iphone, regular movement is detected as shakes.
With the default value of 2.7 for the gravity thing, I had to literally throw my phone into a pillow for it to be detected...

Not quite sure if my phone is broken in this regard, if there's a huge difference between Android/iOS or if it's manufacturer-specific, which would be the worst.

The default value works really well for the iPhone though.

add background shake detection

Thanks for this library, can you make a plugin with service, so I can detect shake on the background as well. is it possible?

Does detect work while travelling?

I saw this package was based on the device acceleration on the x, y, and z axes, based on the code below, it isn't clear from the code below that it's considering to ignore constant accelerations. Or does the shakeThresholdGravity keep that in check?

shake/lib/shake.dart

Lines 62 to 87 in a11b016

double gX = x / 9.80665;
double gY = y / 9.80665;
double gZ = z / 9.80665;
// gForce will be close to 1 when there is no movement.
double gForce = sqrt(gX * gX + gY * gY + gZ * gZ);
if (gForce > shakeThresholdGravity) {
var now = DateTime.now().millisecondsSinceEpoch;
// ignore shake events too close to each other (500ms)
if (mShakeTimestamp + shakeSlopTimeMS > now) {
return;
}
// reset the shake count after 3 seconds of no shakes
if (mShakeTimestamp + shakeCountResetTime < now) {
mShakeCount = 0;
}
mShakeTimestamp = now;
mShakeCount++;
if (mShakeCount >= minimumShakeCount) {
onPhoneShake();
}
}

How to install?

Hello, is this to check when the user shakes the phone?
How to do an installation? I'm used to installing it through pub.dev.
As it happens on Facebook when you shake your phone and a message appears to receive feedback, can you implement it with this package?

Request to Update sensors_plus Dependency to Version ^2.0.0 in Shake Package

HI!
I am using your Shake package in my Flutter project and have encountered a dependency compatibility issue. Specifically, the current version of your package depends on an outdated version of sensors_plus. The latest version of sensors_plus (^2.0.0) includes important updates and improvements that are necessary for my project.

Could you please consider updating the sensors_plus dependency in your package to version ^2.0.0? This will help improve compatibility and stability for users of your package.

Thank you in advance for your attention to this matter and for your work on the Shake package.

update to sensors: ^2.0.0

Because shake 0.1.0 depends on sensors ^0.4.0+1 and no versions of shake match >0.1.0 <0.2.0, shake ^0.1.0 requires sensors ^0.4.0+1.
So, because interview_dvx depends on both shake ^0.1.0 and sensors ^2.0.0, version solving failed.

Getting error setting listener in initState

Hi,

I'm pretty new to flutter so forgive me if this is a noob question but my problem is as follows:

I've added the code exactly as in the example, so I've added it to the initState of my State. when I run the application however i get the following error(s):

E/SensorManager(25422): unregisterListenerImpl callingApp: co.appbrewery.magic8ball,callingPid:25422,callingUid:10261
E/SensorManager(25422): registerListenerImpl sensorName:lsm6ds3c Accelerometer Non-wakeup,isWakeUpSensor:false,callingApp: co.appbrewery.magic8ball,callingPid:25422,callingUid:10261

and my implementation

@override
  void initState() {

    super.initState();

    ShakeDetector detector = ShakeDetector.waitForStart(
        onPhoneShake: () {
          print('shake shake shake');
        }
    );

    detector.startListening();
  }

Do I have to add anything to the AndroidManifest.xml or am I missing anything else?
Hope you can help me out!

Regards Gijs

App crashing when closing it

with the following:

class _ProjectsState extends State {
bool isShowingFavorites = false;

late ShakeDetector detector; <----

@OverRide
void initState() {
super.initState();

detector = ShakeDetector.waitForStart(onPhoneShake: () { <----
  setState(() {
    isShowingFavorites = !isShowingFavorites;
  });
});
detector.startListening(); <----

}

@OverRide
void dispose() {
super.dispose();
detector.stopListening(); <----
}

If I close the app, there is a crash in background...

If I remove the ShakeDetector then it's all good.

Any clue why?

*** Assertion failure in -[FlutterEngine sendOnChannel:message:binaryReply:], FlutterEngine.mm:941
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Sending a message before the FlutterEngine has been run.'
*** First throw call stack:
(0x182075c9c 0x199229758 0x18384621c 0x10b379d70 0x1048227c8 0x1048226a0 0x18377061c 0x183781b14 0x18375c23c 0x18376c31c 0x18376f714 0x18377ce4c 0x181d23ca0 0x181d42198 0x181d19714 0x181d18e40 0x181d262e0 0x181d26abc 0x1dc041e48 0x1dc0419f0)
libc++abi: terminating with uncaught exception of type NSException

  • thread num # 9, queue = 'NSOperationQueue 0x10518af00 (QOS: UNSPECIFIED)', stop reason = signal SIGABRT
    frame #0: 0x00000001bbade9e8 libsystem_kernel.dylib__pthread_kill + 8 libsystem_kernel.dylib__pthread_kill:
    -> 0x1bbade9e8 <+8>: b.lo 0x1bbadea04 ; <+36>
    0x1bbade9ec <+12>: stp x29, x30, [sp, #-0x10]!
    0x1bbade9f0 <+16>: mov x29, sp
    0x1bbade9f4 <+20>: bl 0x1bbada670 ; cerror_nocancel
    Target 0: (Runner) stopped.

Thanks!

Shake event on iOS simulator

I'm using ShakeDetector with default options and it works perfectly on my iPhone. It doesn't seem to detect "shakes" on the iOS simulator (Simulator menu: Device/Shake.) It there anything I can do to make this work?

Shakes not detected

Hi,

I've installed your package, but it's not detecting shakes for some reason.

I've tried both methods to initialise it, but neither seems to work.

I'm using a real device. A pixel 3.

Here are the steps I've taken:

  • Created a brand new flutter project
  • Added shake: ^1.0.0 to pubspec.yaml

main.dart contains the below code.

No errors are output, but shakes are not detected for some reason. Please can you help?

Many thanks.

import 'package:flutter/material.dart';
import 'package:shake/shake.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Shake Test',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Shake Test'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();

    // ShakeDetector detector = ShakeDetector.waitForStart(onPhoneShake: () {
    //   // Do stuff on phone shake
    //   print('shake');
    //   _incrementCounter();
    // });
    // detector.startListening();

    ShakeDetector detector = ShakeDetector.autoStart(onPhoneShake: () {
      // Do stuff on phone shake
      print('shake');
      _incrementCounter();
    });
  }

  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

Switch to using `userAccelerometerEvents`

I see you're working on a newer version which detects events better, but just wanted to say in case you hadn't seen already, that I've been having better success using userAccelerometerEvents instead of accelerometerEvents. This already has the gravyity removed.

I would often find on certain devices that just picking up the phone would trigger the onPhoneShake, but with the userAccelerometerEvents it seems to be much more stable.

Version 2.1.1

Hey!
Could you bump package version and upload it to pub.dev?
Thanks

platform web

Hi. I use this shake package very well.
I made a android application with this and it works nice.
This time, I build web application with same code and it doesn't detect gesture.
I checked this package support web platform in pub.dev.
Is there some more code I should add for web?

https://github.com/kangsudal/whats_for_dinner/blob/main/lib/model/menuState.dart

class MenuState extends ChangeNotifier {
  Recipe? randomRecipe;

  MenuState() {
    ShakeDetector detector = ShakeDetector.autoStart(
      onPhoneShake: () {
        shuffle();
      },
    );
  }

  Future<void> shuffle() async {
    PersistStorage persistStorage = PersistStorage();
    int _maxIdx = await persistStorage.allRecipesLength;
    print("_maxIdx: $_maxIdx, ");
    if (_maxIdx != 0) {
      int _randomIdx = Random().nextInt(_maxIdx);
      print("_randomIdx: $_randomIdx, ");
      randomRecipe = await persistStorage.loadRecipeAt(_randomIdx);
    }else if(_maxIdx ==0){
      randomRecipe = null;
    }
    notifyListeners();
  }
}

https://whateatgo.web.app/

MissingPluginException(No implementation found for method setAccelerationSamplingPeriod on channel dev.fluttercommunity.plus/sensors/method)

I am having this issue when open app:

MissingPluginException(No implementation found for method setAccelerationSamplingPeriod on channel dev.fluttercommunity.plus/sensors/method)

  • Android version: 13.0

  • Plugin version: 2.2.0

  • flutter doctor -v

[✓] Flutter (Channel stable, 3.16.5, on macOS 13.4 22F66 darwin-x64, locale en)
    • Flutter version 3.16.5 on channel stable at /Users/thangnv/fvm/versions/3.16.5
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (2 weeks ago), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2)
    • Android SDK at /Users/thangnv/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (3 available)
    • Pixel 6 (mobile) • 22171FDF6000TB • android-arm64  • Android 13 (API 33)
    • macOS (desktop)  • macos          • darwin-x64     • macOS 13.4 22F66 darwin-x64
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 120.0.6099.129

[✓] Network resources
    • All expected network resources are available.

New version sensors_plus

Can shake use sensors_plus in version 3.1.0?. There are a lot of necessary corrections in it.

How the library works?

We have a int mShakeCount = 0; at shake.dart#L26 that reset in shake.dart#L70 and mShakeCount++ at shake.dart#L74 there is no other usage of this variable , the variable is redundant and if your remove it nothing changed

onPhoneShake calls only gForce > shakeThresholdGravity in each event so it is not technically a shake?! just a rapid movement!

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.