controller.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'dart:io';
  2. import 'package:camera/camera.dart';
  3. import 'package:connectivity_plus/connectivity_plus.dart';
  4. import 'package:get/get.dart';
  5. import 'package:path_provider/path_provider.dart';
  6. import 'package:vitalapp/architecture/defines.dart';
  7. import 'package:vitalapp/architecture/network_connectivity.dart';
  8. import 'package:vitalapp/global.dart';
  9. import 'package:vitalapp/pages/admin/camera_test.dart';
  10. import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
  11. import 'state.dart';
  12. class AdminController extends FControllerBase {
  13. final state = AdminState();
  14. @override
  15. void onInit() {
  16. state.isDeveloper = Get.parameters["role"] == "developer";
  17. state.isNetOnline = kIsOnline;
  18. state.isDeviceLogEnable = VnoteDevicePluginPlatform.instance.isLogEnable;
  19. netChecker.onlineChangedEvent.addListener(_onNetOnlineChanged);
  20. super.onInit();
  21. }
  22. @override
  23. void onReady() {
  24. // TODO: implement onReady
  25. super.onReady();
  26. }
  27. @override
  28. void dispose() {
  29. netChecker.onlineChangedEvent.removeListener(_onNetOnlineChanged);
  30. super.dispose();
  31. }
  32. void cpDbFileLoki() async {
  33. var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
  34. final directory = await getExternalStorageDirectory();
  35. final path = directory?.path;
  36. final sourceFile = File(sPath);
  37. final destFile = File('$path/vital.db');
  38. await destFile.create(recursive: true);
  39. await sourceFile.copy(destFile.path);
  40. }
  41. void cpDbFileFinlay() async {
  42. var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
  43. final directory = await getExternalStorageDirectory();
  44. final path = directory?.path;
  45. final destFile = File('$path/vital.db');
  46. final sourceFile = File(sPath);
  47. await destFile.copy(sourceFile.path);
  48. }
  49. void switchOnlineOffline() {
  50. NetworkConnectivityChecker.customNetStatus = true;
  51. NetworkConnectivityChecker.customUpdateStatus(
  52. kIsOnline ? ConnectivityResult.none : ConnectivityResult.wifi,
  53. );
  54. }
  55. void setLogSwitch() async {
  56. final isEnable = !state.isDeviceLogEnable;
  57. await VnoteDevicePluginPlatform.instance.setLogEnable(isEnable);
  58. state.isDeviceLogEnable = isEnable;
  59. }
  60. void _onNetOnlineChanged(_, bool val) {
  61. state.isNetOnline = val;
  62. }
  63. void detectCamera() async {
  64. state.cameraList.clear();
  65. try {
  66. final _cameras = await availableCameras();
  67. for (final camera in _cameras) {
  68. state.cameraList.add(camera.toString());
  69. }
  70. } catch (e) {
  71. state.errorMessage.value = e.toString();
  72. }
  73. }
  74. void openCameraTest() async {
  75. await Get.to(() => const CameraTest());
  76. }
  77. }