shake_detector 0.1.2 copy "shake_detector: ^0.1.2" to clipboard
shake_detector: ^0.1.2 copied to clipboard

a configurable package to detect shake gestures, using the sensors_plus package.

example/lib/main.dart

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

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Shake Detector'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _shakeCount = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: ShakeDetectWrap(
        onShake: () {
          setState(() {
            _shakeCount++;
          });
        },
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'Shake your phone to see the shake count',
              ),
              Text(
                '$_shakeCount',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
9
likes
130
pub points
84%
popularity

Publisher

verified publisherfolksable.com

a configurable package to detect shake gestures, using the sensors_plus package.

Repository (GitHub)
View/report issues

Topics

#sensors #shake #gestures

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (LICENSE)

Dependencies

flutter, sensors_plus

More

Packages that depend on shake_detector