flet-flashlight 0.1.0.dev1__py3-none-any.whl → 0.2.0.dev30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flet-flashlight might be problematic. Click here for more details.
- flet_flashlight/__init__.py +10 -1
- flet_flashlight/exceptions.py +54 -0
- flet_flashlight/flashlight.py +90 -75
- flet_flashlight-0.2.0.dev30.dist-info/METADATA +62 -0
- flet_flashlight-0.2.0.dev30.dist-info/RECORD +17 -0
- {flet_flashlight-0.1.0.dev1.dist-info → flet_flashlight-0.2.0.dev30.dist-info}/WHEEL +1 -1
- flet_flashlight-0.2.0.dev30.dist-info/licenses/LICENSE +201 -0
- flutter/flet_flashlight/lib/flet_flashlight.dart +1 -1
- flutter/flet_flashlight/lib/src/extension.dart +15 -0
- flutter/flet_flashlight/lib/src/flashlight.dart +89 -50
- flutter/flet_flashlight/pubspec.lock +167 -118
- flutter/flet_flashlight/pubspec.yaml +8 -3
- flet_flashlight-0.1.0.dev1.dist-info/METADATA +0 -39
- flet_flashlight-0.1.0.dev1.dist-info/RECORD +0 -15
- flutter/flet_flashlight/lib/src/create_control.dart +0 -20
- {flet_flashlight-0.1.0.dev1.dist-info → flet_flashlight-0.2.0.dev30.dist-info}/top_level.txt +0 -0
|
@@ -1,62 +1,101 @@
|
|
|
1
|
-
import 'dart:io' show Platform;
|
|
2
|
-
import 'dart:io';
|
|
3
|
-
|
|
4
1
|
import 'package:flet/flet.dart';
|
|
5
2
|
import 'package:flutter/widgets.dart';
|
|
6
3
|
import 'package:torch_light/torch_light.dart';
|
|
7
4
|
|
|
8
|
-
class FlashlightControl extends
|
|
9
|
-
|
|
10
|
-
final Control control;
|
|
11
|
-
final Widget? nextChild;
|
|
12
|
-
final FletControlBackend backend;
|
|
13
|
-
|
|
14
|
-
const FlashlightControl(
|
|
15
|
-
{super.key,
|
|
16
|
-
required this.parent,
|
|
17
|
-
required this.control,
|
|
18
|
-
required this.nextChild,
|
|
19
|
-
required this.backend});
|
|
20
|
-
|
|
21
|
-
@override
|
|
22
|
-
State<FlashlightControl> createState() => _FlashlightControlState();
|
|
23
|
-
}
|
|
5
|
+
class FlashlightControl extends FletService {
|
|
6
|
+
FlashlightControl({required super.control});
|
|
24
7
|
|
|
25
|
-
class _FlashlightControlState extends State<FlashlightControl> {
|
|
26
8
|
@override
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
void init() {
|
|
10
|
+
super.init();
|
|
11
|
+
debugPrint("Flashlight(${control.id}).init: ${control.properties}");
|
|
12
|
+
control.addInvokeMethodListener(_invokeMethod);
|
|
13
|
+
}
|
|
29
14
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
15
|
+
Future<dynamic> _invokeMethod(String name, dynamic args) async {
|
|
16
|
+
debugPrint("Flashlight.$name($args)");
|
|
17
|
+
if (isMobilePlatform()) {
|
|
18
|
+
Map<String, String?>? errorInfo;
|
|
19
|
+
switch (name) {
|
|
20
|
+
case "on":
|
|
21
|
+
try {
|
|
22
|
+
await TorchLight.enableTorch();
|
|
23
|
+
return true;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (e is EnableTorchExistentUserException) {
|
|
26
|
+
errorInfo = {
|
|
27
|
+
"error_type": "EnableTorchExistentUserException",
|
|
28
|
+
"error_msg": e.message
|
|
29
|
+
};
|
|
30
|
+
} else if (e is EnableTorchNotAvailableException) {
|
|
31
|
+
errorInfo = {
|
|
32
|
+
"error_type": "EnableTorchNotAvailableException",
|
|
33
|
+
"error_msg": e.message
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
errorInfo = {
|
|
37
|
+
"error_type": "EnableTorchException",
|
|
38
|
+
"error_msg": (e as EnableTorchException).message
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
control.triggerEvent("error", errorInfo);
|
|
42
|
+
debugPrint(
|
|
43
|
+
"Error enabling Flashlight: ${errorInfo["error_type"]}(${errorInfo["error_msg"]})");
|
|
44
|
+
return errorInfo;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
case "off":
|
|
47
|
+
try {
|
|
48
|
+
await TorchLight.disableTorch();
|
|
49
|
+
return true;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e is DisableTorchExistentUserException) {
|
|
52
|
+
errorInfo = {
|
|
53
|
+
"error_type": "DisableTorchExistentUserException",
|
|
54
|
+
"error_msg": e.message
|
|
55
|
+
};
|
|
56
|
+
} else if (e is DisableTorchNotAvailableException) {
|
|
57
|
+
errorInfo = {
|
|
58
|
+
"error_type": "DisableTorchNotAvailableException",
|
|
59
|
+
"error_msg": e.message
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
62
|
+
errorInfo = {
|
|
63
|
+
"error_type": "DisableTorchException",
|
|
64
|
+
"error_msg": (e as DisableTorchException).message
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
control.triggerEvent("error", errorInfo);
|
|
68
|
+
debugPrint(
|
|
69
|
+
"Error disabling Flashlight: ${errorInfo["error_type"]}(${errorInfo["error_msg"]})");
|
|
70
|
+
return errorInfo;
|
|
71
|
+
}
|
|
72
|
+
case "is_available":
|
|
73
|
+
try {
|
|
74
|
+
final available = await TorchLight.isTorchAvailable();
|
|
75
|
+
return available;
|
|
76
|
+
} on EnableTorchException catch (e) {
|
|
77
|
+
errorInfo = {
|
|
78
|
+
"error_type": "EnableTorchException",
|
|
79
|
+
"error_msg": e.message
|
|
80
|
+
};
|
|
81
|
+
control.triggerEvent("error", errorInfo);
|
|
82
|
+
debugPrint(
|
|
83
|
+
"Error checking Flashlight availability: EnableTorchException(${e.message})");
|
|
84
|
+
return errorInfo;
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
throw Exception("Unknown Flashlight method: $name");
|
|
88
|
+
}
|
|
57
89
|
} else {
|
|
58
|
-
|
|
59
|
-
"
|
|
90
|
+
throw Exception(
|
|
91
|
+
"Flashlight control is supported only on Android and iOS devices.");
|
|
60
92
|
}
|
|
61
93
|
}
|
|
94
|
+
|
|
95
|
+
@override
|
|
96
|
+
void dispose() {
|
|
97
|
+
debugPrint("Flashlight(${control.id}).dispose");
|
|
98
|
+
control.removeInvokeMethodListener(_invokeMethod);
|
|
99
|
+
super.dispose();
|
|
100
|
+
}
|
|
62
101
|
}
|