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();
  }
}
200
likes
140
points
30.6k
downloads

Publisher

verified publisherjoshi.dev

Weekly Downloads

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