Advertisement
toennito

Swipe-Button

May 8th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.08 KB | None | 0 0
  1.   final Element p = querySelector('#sniffer');
  2.   int act1X, act1XStart, act1Y, act1YStart, diffX, diffY;
  3.   String action1 = "1";
  4.   querySelector("#action1")
  5.     ..onTouchStart.listen((TouchEvent e) {
  6.       act1XStart = e.touches.first.page.x;
  7.       act1YStart = e.touches.first.page.y;
  8.       act1X = e.touches.last.page.x;
  9.       act1Y = e.touches.last.page.y;
  10.     })
  11.     ..onTouchMove.listen((TouchEvent e) {
  12.       act1X = e.touches.last.page.x;
  13.       act1Y = e.touches.last.page.y;
  14.     })
  15.     ..onTouchEnd.listen((TouchEvent e) {
  16.       diffX = act1X - act1XStart;
  17.       diffY = act1Y - act1YStart;
  18.       if (diffX.abs() < 10 && diffY.abs() < 10) {
  19.         print("ACTION $action1");
  20.         p.appendText(action1);
  21.       } else if (diffX.abs() < diffY.abs()) {
  22.         if (diffY.isNegative) {
  23.           action1 = "1";
  24.         } else {
  25.           action1 = "3";
  26.         }
  27.       } else {
  28.         if (diffX.isNegative) {
  29.           action1 = "4";
  30.         } else {
  31.           action1 = "2";
  32.         }
  33.       }
  34.       querySelector("#action1").setAttribute("value", action1);
  35.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement