|
|
@@ -9,6 +9,8 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
9
|
9
|
import 'package:flutter_zsdk/src/models/bluetooth_printer.dart';
|
|
10
|
10
|
import 'package:flutter_zsdk/src/models/error_code.dart';
|
|
11
|
11
|
import 'package:flutter_zsdk/src/models/flutter_zsdk_exception.dart';
|
|
|
12
|
+import 'package:location/location.dart' as loca;
|
|
|
13
|
+// import 'package:geolocator/geolocator.dart';
|
|
12
|
14
|
import 'package:permission_handler/permission_handler.dart';
|
|
13
|
15
|
|
|
14
|
16
|
import 'flutter_zsdk_platform_interface.dart';
|
|
|
@@ -48,12 +50,25 @@ class MethodChannelFlutterZsdk extends FlutterZsdkPlatform {
|
|
48
|
50
|
await FlutterBluePlus.turnOn();
|
|
49
|
51
|
} on FlutterBluePlusException catch (e) {
|
|
50
|
52
|
throw FlutterZsdkException(ErrorCode.turnOnBluetoothError, "Failed to turn on bluetooth: ${e.description}");
|
|
|
53
|
+ } catch (e) {
|
|
|
54
|
+ throw FlutterZsdkException(ErrorCode.turnOnBluetoothError, "Failed to turn on bluetooth");
|
|
51
|
55
|
}
|
|
52
|
56
|
} else {
|
|
53
|
57
|
throw FlutterZsdkException(ErrorCode.bluetoothDisabled, "Bluetooth is not turned on on this device.");
|
|
54
|
58
|
}
|
|
55
|
59
|
}
|
|
56
|
60
|
|
|
|
61
|
+ // check location service
|
|
|
62
|
+ bool serviceEnabled = await loca.Location.instance.serviceEnabled();
|
|
|
63
|
+
|
|
|
64
|
+ if (!serviceEnabled) {
|
|
|
65
|
+ var serviceEnabled = await loca.Location.instance.requestService();
|
|
|
66
|
+ if (!serviceEnabled) {
|
|
|
67
|
+ throw FlutterZsdkException(ErrorCode.locationServiceDisabled, "This app require location service to scan bluetooth printers, please turn on location service first");
|
|
|
68
|
+ }
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+
|
|
57
|
72
|
var bluetoothPermissionStatus = await Permission.bluetooth.status;
|
|
58
|
73
|
var bluetoothConnectPermissionStatus = await Permission.bluetoothConnect.status;
|
|
59
|
74
|
var bluetoothScanPermissionStatus = await Permission.bluetoothScan.status;
|
|
|
@@ -74,6 +89,16 @@ class MethodChannelFlutterZsdk extends FlutterZsdkPlatform {
|
|
74
|
89
|
|
|
75
|
90
|
if (permissionStatuses[Permission.bluetooth] == PermissionStatus.granted && permissionStatuses[Permission.bluetoothConnect] == PermissionStatus.granted && permissionStatuses[Permission.bluetoothScan] == PermissionStatus.granted && permissionStatuses[Permission.location] == PermissionStatus.granted) {
|
|
76
|
91
|
return bluetoothDiscoveryEventChannel.receiveBroadcastStream();
|
|
|
92
|
+
|
|
|
93
|
+ } else if (permissionStatuses[Permission.bluetoothConnect] != PermissionStatus.granted && permissionStatuses[Permission.bluetoothScan] != PermissionStatus.granted) {
|
|
|
94
|
+ throw FlutterZsdkException(ErrorCode.nearbyDeviceAccessPermissionNotGranted, "Nearby device access permission not granted, please allow permission to discover bluetooth printers.");
|
|
|
95
|
+
|
|
|
96
|
+ } else if (permissionStatuses[Permission.bluetooth] != PermissionStatus.granted) {
|
|
|
97
|
+ throw FlutterZsdkException(ErrorCode.bluetoothPermissionDenied, "Bluetooth permission not granted, please allow permission to discover bluetooth printers.");
|
|
|
98
|
+
|
|
|
99
|
+ } else if (permissionStatuses[Permission.location] != PermissionStatus.granted) {
|
|
|
100
|
+ throw FlutterZsdkException(ErrorCode.locationPermissionDenied, "Location permission not granted, please allow permission to discover bluetooth printers.");
|
|
|
101
|
+
|
|
77
|
102
|
} else {
|
|
78
|
103
|
// throw Exception("Permissions not granted, please allow permission to discover bluetooth printers.");
|
|
79
|
104
|
throw FlutterZsdkException(ErrorCode.permissionNotGranted, "Permissions not granted, please allow permission to discover bluetooth printers.");
|