wiredash-sdk icon indicating copy to clipboard operation
wiredash-sdk copied to clipboard

Trigger Wiredash when device is shaken

Open IchordeDionysos opened this issue 5 years ago • 2 comments

Wiredash should support triggering it by shaking the phone.

It's possible to do that currently on our own, with some drawback, see #62

IchordeDionysos avatar Jul 04 '20 22:07 IchordeDionysos

agreed, this should be easy or even default like some/most services of this sort

neiljaywarner avatar Oct 25 '20 22:10 neiljaywarner

I don't think this should be part of Wiredash. Adding the functionality is trivial:

import 'package:die_ringe_workout/util/crashlytics.dart';
import 'package:die_ringe_workout/util/sharedpreferences.dart';
import 'package:flutter/material.dart';
import 'package:shake/shake.dart';
import 'package:wiredash/wiredash.dart';

class ShakeToWiredash extends StatefulWidget {
  final Widget child;

  const ShakeToWiredash({
    super.key,
    required this.child,
  });

  @override
  State<ShakeToWiredash> createState() => _ShakeToWiredashState();
}

class _ShakeToWiredashState extends State<ShakeToWiredash> {
  late final _detector = ShakeDetector.waitForStart(
    onPhoneShake: () async {
      final isEnabled = true; // <-- add own logic here

      logEvent("User shook the phone. Showing Wiredash: $isEnabled");
      if (!isEnabled) return;

      if (!mounted) return;
      Wiredash.of(context).show();
    },
    // Add your own params here
    minimumShakeCount: 3,
    shakeCountResetTime: 2000,
    shakeSlopTimeMS: 250,
  );

  @override
  void initState() {
    super.initState();
    _detector.startListening();
  }

  @override
  void dispose() {
    _detector.stopListening();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}

The difficult part is figuring out which shake parameters work for you. If it's an internal app you might want easy, frequent feedback, if it's an app for end users you might want to add a little more friction to prevent triggering it accidentally.

Imo this can be closed.

ciriousjoker avatar Feb 05 '23 15:02 ciriousjoker