shake 2.2.0 copy "shake: ^2.2.0" to clipboard
shake: ^2.2.0 copied to clipboard

A flutter package to detect phone shakes. Adjustable G-force and reset periods.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: DemoPage(),
    );
  }
}

class DemoPage extends StatefulWidget {
  @override
  _DemoPageState createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  @override
  void initState() {
    super.initState();
    ShakeDetector detector = ShakeDetector.autoStart(
      onPhoneShake: () {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(
            content: Text('Shake!'),
          ),
        );
        // Do stuff on phone shake
      },
      minimumShakeCount: 1,
      shakeSlopTimeMS: 500,
      shakeCountResetTime: 3000,
      shakeThresholdGravity: 2.7,
    );

    // To close: detector.stopListening();
    // ShakeDetector.waitForStart() waits for user to call detector.startListening();
  }

  @override
  Widget build(BuildContext context) {
    return const Scaffold();
  }
}
192
likes
120
pub points
98%
popularity

Publisher

verified publisherjoshi.dev

A flutter package to detect phone shakes. Adjustable G-force and reset periods.

Repository

Documentation

API reference

License

BSD-2-Clause (LICENSE)

Dependencies

flutter, sensors_plus

More

Packages that depend on shake