wiredashio / wiredash-sdk

Interactive user feedback tool for Flutter 🎉
https://pub.dev/packages/wiredash
Other
514 stars 67 forks source link

Trigger Wiredash when device is shaken #63

Open IchordeDionysos opened 4 years ago

IchordeDionysos commented 4 years ago

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 commented 4 years ago

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

ciriousjoker commented 1 year ago

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.