Spaces:
Paused
Paused
Commit ·
6f0e7f2
1
Parent(s): 4e252d0
added repeat for web vibrate and made it consistent for both web and mobile
Browse files- client/lib/HomeScreen.dart +14 -5
- client/lib/vibrate_web.dart +9 -1
- client/web/app.js +31 -0
client/lib/HomeScreen.dart
CHANGED
|
@@ -593,25 +593,34 @@ class HomeScreenState extends State<HomeScreen>{
|
|
| 593 |
if(kIsWeb){
|
| 594 |
// different handler for web
|
| 595 |
// showSnackBar("web");
|
| 596 |
-
Vibration.vibrate(pattern:[100,100,20]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
// HapticFeedback.heavyImpact();
|
| 598 |
}
|
| 599 |
else{
|
| 600 |
// showSnackBar("mobile");
|
| 601 |
if (await Vibration.hasVibrator()==true) {
|
| 602 |
-
|
| 603 |
-
|
|
|
|
| 604 |
}
|
| 605 |
}
|
| 606 |
|
| 607 |
}
|
| 608 |
-
void endHapticFeedback()
|
| 609 |
if(kIsWeb){
|
| 610 |
// different handler for web
|
| 611 |
Vibration.cancel();
|
| 612 |
}
|
| 613 |
else{
|
| 614 |
-
if (
|
| 615 |
Vibration.cancel();
|
| 616 |
}
|
| 617 |
}
|
|
|
|
| 593 |
if(kIsWeb){
|
| 594 |
// different handler for web
|
| 595 |
// showSnackBar("web");
|
| 596 |
+
// Vibration.vibrate(pattern:[100,100,20]);
|
| 597 |
+
// Vibration.vibrate(pattern:[1000,1000,200]);
|
| 598 |
+
// off,on,off
|
| 599 |
+
Vibration.vibrate(pattern:[20,100], repeat: 0); // short fast
|
| 600 |
+
// Vibration.vibrate(pattern:[200,2000,200], repeat: 0); // short fast
|
| 601 |
+
|
| 602 |
+
// Vibration.vibrate(pattern:[0,20,100,30], repeat: 0); // short fast
|
| 603 |
+
// Vibration.vibrate(pattern:[20,100,30], repeat: 0); // short fast
|
| 604 |
+
|
| 605 |
// HapticFeedback.heavyImpact();
|
| 606 |
}
|
| 607 |
else{
|
| 608 |
// showSnackBar("mobile");
|
| 609 |
if (await Vibration.hasVibrator()==true) {
|
| 610 |
+
// off,on,off
|
| 611 |
+
Vibration.vibrate(pattern:[20,100], repeat: 0); // short fast
|
| 612 |
+
// Vibration.vibrate(pattern:[100, 200, 400],repeat: 0); // slow
|
| 613 |
}
|
| 614 |
}
|
| 615 |
|
| 616 |
}
|
| 617 |
+
void endHapticFeedback(){
|
| 618 |
if(kIsWeb){
|
| 619 |
// different handler for web
|
| 620 |
Vibration.cancel();
|
| 621 |
}
|
| 622 |
else{
|
| 623 |
+
if (Vibration.hasVibrator()==true) {
|
| 624 |
Vibration.cancel();
|
| 625 |
}
|
| 626 |
}
|
client/lib/vibrate_web.dart
CHANGED
|
@@ -7,8 +7,16 @@ import 'package:flutter/material.dart';
|
|
| 7 |
class Vibration{
|
| 8 |
|
| 9 |
static void vibrate({List<int> pattern=const [100],int repeat=-1}){
|
|
|
|
|
|
|
| 10 |
var jsArray = js.JsObject.jsify(pattern);
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
static Future<bool> hasVibrator(){
|
|
|
|
| 7 |
class Vibration{
|
| 8 |
|
| 9 |
static void vibrate({List<int> pattern=const [100],int repeat=-1}){
|
| 10 |
+
|
| 11 |
+
pattern=[1]+pattern; // to change it match vibrating pattern of android which is (off,on,off,on,off,...)
|
| 12 |
var jsArray = js.JsObject.jsify(pattern);
|
| 13 |
+
if(repeat==-1){
|
| 14 |
+
//on,off,on,off,on
|
| 15 |
+
js.context.callMethod('vibrate', [jsArray]);
|
| 16 |
+
}
|
| 17 |
+
else{
|
| 18 |
+
js.context.callMethod('peristentVibrate', [jsArray]);
|
| 19 |
+
}
|
| 20 |
}
|
| 21 |
|
| 22 |
static Future<bool> hasVibrator(){
|
client/web/app.js
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
|
|
|
|
|
| 1 |
function vibrate(flutter_value) {
|
|
|
|
|
|
|
| 2 |
if ("vibrate" in navigator){
|
| 3 |
// alert("supported");
|
| 4 |
navigator.vibrate(flutter_value);
|
| 5 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 1 |
+
var vibrateInterval;
|
| 2 |
+
|
| 3 |
function vibrate(flutter_value) {
|
| 4 |
+
clearInterval(vibrateInterval);
|
| 5 |
+
|
| 6 |
if ("vibrate" in navigator){
|
| 7 |
// alert("supported");
|
| 8 |
navigator.vibrate(flutter_value);
|
| 9 |
}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
function sum(arr1){
|
| 13 |
+
if(arr1.constructor !== Array) return arr1
|
| 14 |
+
|
| 15 |
+
function add(accumulator, a) {
|
| 16 |
+
return accumulator + a;
|
| 17 |
+
}
|
| 18 |
+
sumvalue = arr1.reduce(add, 0);
|
| 19 |
+
return sumvalue;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function setIntervalAndExecute(fn, t) {
|
| 23 |
+
fn();
|
| 24 |
+
return(setInterval(fn, t));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function peristentVibrate(pattern) {
|
| 28 |
+
|
| 29 |
+
// alert("supported");
|
| 30 |
+
// vibrateInterval = setInterval(() => {
|
| 31 |
+
vibrateInterval = setIntervalAndExecute(() => {
|
| 32 |
+
if ("vibrate" in navigator){
|
| 33 |
+
navigator.vibrate(pattern);
|
| 34 |
+
}
|
| 35 |
+
}, sum(pattern));
|
| 36 |
+
|
| 37 |
}
|