controller.dart 2.8 KB

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