Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger Wiredash when device is shaken #63

Open
IchordeDionysos opened this issue Jul 4, 2020 · 2 comments
Open

Trigger Wiredash when device is shaken #63

IchordeDionysos opened this issue Jul 4, 2020 · 2 comments
Labels
feature request New feature or request sdk This issue affects the sdk

Comments

@IchordeDionysos
Copy link

Wiredash should support triggering it by shaking the phone.

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

@neiljaywarner
Copy link

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

@flschweiger flschweiger added feature request New feature or request sdk This issue affects the sdk labels Nov 10, 2020
@ciriousjoker
Copy link
Contributor

ciriousjoker commented Feb 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request sdk This issue affects the sdk
Projects
None yet
Development

No branches or pull requests

4 participants