deven98 / shake

A flutter package for detecting phone shakes.
BSD 2-Clause "Simplified" License
92 stars 52 forks source link

platform web #13

Open kangsudal opened 2 years ago

kangsudal commented 2 years ago

Hi. I use this shake package very well. I made a android application with this and it works nice. This time, I build web application with same code and it doesn't detect gesture. I checked this package support web platform in pub.dev. Is there some more code I should add for web?

https://github.com/kangsudal/whats_for_dinner/blob/main/lib/model/menuState.dart

class MenuState extends ChangeNotifier {
  Recipe? randomRecipe;

  MenuState() {
    ShakeDetector detector = ShakeDetector.autoStart(
      onPhoneShake: () {
        shuffle();
      },
    );
  }

  Future<void> shuffle() async {
    PersistStorage persistStorage = PersistStorage();
    int _maxIdx = await persistStorage.allRecipesLength;
    print("_maxIdx: $_maxIdx, ");
    if (_maxIdx != 0) {
      int _randomIdx = Random().nextInt(_maxIdx);
      print("_randomIdx: $_randomIdx, ");
      randomRecipe = await persistStorage.loadRecipeAt(_randomIdx);
    }else if(_maxIdx ==0){
      randomRecipe = null;
    }
    notifyListeners();
  }
}

https://whateatgo.web.app/

deven98 commented 2 years ago

This should work with v2.1.0, can you try and let me know if it works?

kangsudal commented 2 years ago

oh!! awesome!!!!!! it works! my version was ^1.0.1 so I change it to ^2.1.0 in yaml. I appreciate your answer and this package. 😃

kangsudal commented 2 years ago

As soon as I write this, I gave my updated web app link to others. In device(Galaxy A50, Galaxy M12) with samsung web browser and chrome, it works very well. But some friends said it still did't work. One person(iphone11) uses safari so I asked her to test it in chrome and it didn't work too. The other(Galaxy A5 2017 ) told me it works with samung web browser and doesn't work in chrome.

After some try, I found out and solve it in chrome browser in Galaxy A5: Settings-Site settings-Motion sensors: allowed

Unfortunatelly, I can't find the setting page in iphone chrome/safari yet. Do know where is the setting page and how to fix it in iphone?