Spaces:
Sleeping
Sleeping
Commit ·
f7e388c
1
Parent(s): 6d1f94e
added conditional import for web/mobile vibration package
Browse files- client/lib/HomeScreen.dart +6 -7
- client/lib/vibrate_web.dart +11 -6
- client/pubspec.yaml +1 -0
client/lib/HomeScreen.dart
CHANGED
|
@@ -9,11 +9,10 @@ import 'package:web_socket_channel/status.dart' as status;
|
|
| 9 |
|
| 10 |
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
| 11 |
|
| 12 |
-
import 'package:vibration/vibration.dart'; // for the haptics
|
| 13 |
-
// import 'package:vibration_web/vibration_web.dart'; // for haptics on web
|
| 14 |
-
import 'vibrate_web.dart'; // for haptics on web
|
| 15 |
-
|
| 16 |
import 'package:flutter/foundation.dart' show kIsWeb; // to check of platform is web
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
import "dart:convert";
|
| 19 |
import "dart:async";
|
|
@@ -577,8 +576,8 @@ class HomeScreenState extends State<HomeScreen>{
|
|
| 577 |
|
| 578 |
if(kIsWeb){
|
| 579 |
// different handler for web
|
| 580 |
-
//
|
| 581 |
-
|
| 582 |
// HapticFeedback.heavyImpact();
|
| 583 |
}
|
| 584 |
else{
|
|
@@ -592,7 +591,7 @@ class HomeScreenState extends State<HomeScreen>{
|
|
| 592 |
void endHapticFeedback() async{
|
| 593 |
if(kIsWeb){
|
| 594 |
// different handler for web
|
| 595 |
-
|
| 596 |
}
|
| 597 |
else{
|
| 598 |
if (await Vibration.hasVibrator()==true) {
|
|
|
|
| 9 |
|
| 10 |
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import 'package:flutter/foundation.dart' show kIsWeb; // to check of platform is web
|
| 13 |
+
// import 'vibrate_web.dart' if(kIsWeb) "'package:vibration/vibration.dart'"; // import based on platform
|
| 14 |
+
import 'package:vibration/vibration.dart' if(kIsWeb) 'vibrate_web.dart'; // import based on platform
|
| 15 |
+
|
| 16 |
|
| 17 |
import "dart:convert";
|
| 18 |
import "dart:async";
|
|
|
|
| 576 |
|
| 577 |
if(kIsWeb){
|
| 578 |
// different handler for web
|
| 579 |
+
// Vibration.test();
|
| 580 |
+
Vibration.vibrate(pattern:[100,100,20]);
|
| 581 |
// HapticFeedback.heavyImpact();
|
| 582 |
}
|
| 583 |
else{
|
|
|
|
| 591 |
void endHapticFeedback() async{
|
| 592 |
if(kIsWeb){
|
| 593 |
// different handler for web
|
| 594 |
+
Vibration.cancel();
|
| 595 |
}
|
| 596 |
else{
|
| 597 |
if (await Vibration.hasVibrator()==true) {
|
client/lib/vibrate_web.dart
CHANGED
|
@@ -1,16 +1,21 @@
|
|
| 1 |
-
import 'dart:js'
|
|
|
|
| 2 |
// import 'dart:async';
|
| 3 |
|
| 4 |
|
| 5 |
-
class
|
| 6 |
|
| 7 |
-
static void vibrate({List<int> pattern=const [100]}){
|
| 8 |
|
| 9 |
-
var jsArray =
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
static void cancel(){
|
| 14 |
-
|
| 15 |
}
|
| 16 |
}
|
|
|
|
| 1 |
+
import 'dart:js';
|
| 2 |
+
// import 'dart:io' if (dart.library.html) 'dart:html';
|
| 3 |
// import 'dart:async';
|
| 4 |
|
| 5 |
|
| 6 |
+
class Vibration{
|
| 7 |
|
| 8 |
+
static void vibrate({List<int> pattern=const [100],int repeat=-1}){
|
| 9 |
|
| 10 |
+
var jsArray = JsObject.jsify(pattern);
|
| 11 |
+
context.callMethod('vibrate', [jsArray]);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
static Future<bool> hasVibrator() async{
|
| 15 |
+
return await context['navigator'].hasProperty("vibrate");
|
| 16 |
}
|
| 17 |
|
| 18 |
static void cancel(){
|
| 19 |
+
context.callMethod('vibrate', [0]);
|
| 20 |
}
|
| 21 |
}
|
client/pubspec.yaml
CHANGED
|
@@ -11,6 +11,7 @@ dependencies:
|
|
| 11 |
flutter:
|
| 12 |
sdk: flutter
|
| 13 |
flutter_colorpicker: ^1.0.3
|
|
|
|
| 14 |
shared_preferences: ^2.2.2
|
| 15 |
vibration: ^1.8.3
|
| 16 |
web_socket_channel: ^2.4.0
|
|
|
|
| 11 |
flutter:
|
| 12 |
sdk: flutter
|
| 13 |
flutter_colorpicker: ^1.0.3
|
| 14 |
+
js: ^0.6.5
|
| 15 |
shared_preferences: ^2.2.2
|
| 16 |
vibration: ^1.8.3
|
| 17 |
web_socket_channel: ^2.4.0
|