controller.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'dart:io';
  2. import 'package:connectivity_plus/connectivity_plus.dart';
  3. import 'package:get/get.dart';
  4. import 'package:path_provider/path_provider.dart';
  5. import 'package:vitalapp/architecture/defines.dart';
  6. import 'package:vitalapp/architecture/network_connectivity.dart';
  7. import 'package:vitalapp/global.dart';
  8. import 'package:vitalapp/routes/routes.dart';
  9. import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
  10. import 'state.dart';
  11. class AdminController extends FControllerBase {
  12. final state = AdminState();
  13. @override
  14. void onInit() {
  15. state.isDeveloper = Get.parameters["role"] == "developer";
  16. state.isNetOnline = kIsOnline;
  17. state.isDeviceLogEnable = VnoteDevicePluginPlatform.instance.isLogEnable;
  18. netChecker.onlineChangedEvent.addListener(_onNetOnlineChanged);
  19. super.onInit();
  20. }
  21. @override
  22. void onReady() {
  23. // TODO: implement onReady
  24. super.onReady();
  25. }
  26. @override
  27. void dispose() {
  28. netChecker.onlineChangedEvent.removeListener(_onNetOnlineChanged);
  29. super.dispose();
  30. }
  31. void cpDbFileLoki() async {
  32. var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
  33. final directory = await getExternalStorageDirectory();
  34. final path = directory?.path;
  35. final sourceFile = File(sPath);
  36. final destFile = File('$path/vital.db');
  37. await destFile.create(recursive: true);
  38. await sourceFile.copy(destFile.path);
  39. }
  40. void cpDbFileFinlay() async {
  41. var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
  42. final directory = await getExternalStorageDirectory();
  43. final path = directory?.path;
  44. final destFile = File('$path/vital.db');
  45. final sourceFile = File(sPath);
  46. await destFile.copy(sourceFile.path);
  47. }
  48. void switchOnlineOffline() {
  49. NetworkConnectivityChecker.customNetStatus = true;
  50. NetworkConnectivityChecker.customUpdateStatus(
  51. kIsOnline ? ConnectivityResult.none : ConnectivityResult.wifi,
  52. );
  53. }
  54. void setLogSwitch() async {
  55. final isEnable = !state.isDeviceLogEnable;
  56. await VnoteDevicePluginPlatform.instance.setLogEnable(isEnable);
  57. state.isDeviceLogEnable = isEnable;
  58. }
  59. void _onNetOnlineChanged(_, bool val) {
  60. state.isNetOnline = val;
  61. }
  62. }