1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import 'dart:io';
- import 'package:camera/camera.dart';
- import 'package:connectivity_plus/connectivity_plus.dart';
- import 'package:get/get.dart';
- import 'package:path_provider/path_provider.dart';
- import 'package:vitalapp/architecture/defines.dart';
- import 'package:vitalapp/architecture/network_connectivity.dart';
- import 'package:vitalapp/global.dart';
- import 'package:vitalapp/pages/admin/camera_test.dart';
- import 'package:vitalapp/pages/admin/usb_state.dart';
- import 'package:vitalapp/routes/routes.dart';
- import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
- import 'state.dart';
- class AdminController extends FControllerBase {
- final state = AdminState();
- @override
- void onInit() {
- state.isDeveloper = Get.parameters["role"] == "developer";
- state.isNetOnline = kIsOnline;
- state.isDeviceLogEnable = VnoteDevicePluginPlatform.instance.isLogEnable;
- netChecker.onlineChangedEvent.addListener(_onNetOnlineChanged);
- UsbState usbState = UsbState();
- usbState.startListening();
- super.onInit();
- }
- @override
- void onReady() {
- // TODO: implement onReady
- super.onReady();
- }
- @override
- void dispose() {
- netChecker.onlineChangedEvent.removeListener(_onNetOnlineChanged);
- super.dispose();
- }
- void cpDbFileLoki() async {
- var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
- final directory = await getExternalStorageDirectory();
- final path = directory?.path;
- final sourceFile = File(sPath);
- final destFile = File('$path/vital.db');
- await destFile.create(recursive: true);
- await sourceFile.copy(destFile.path);
- }
- void cpDbFileFinlay() async {
- var sPath = "/data/user/0/com.vinno.vitalapp/databases/vital.db";
- final directory = await getExternalStorageDirectory();
- final path = directory?.path;
- final destFile = File('$path/vital.db');
- final sourceFile = File(sPath);
- await destFile.copy(sourceFile.path);
- }
- void switchOnlineOffline() {
- NetworkConnectivityChecker.customNetStatus = true;
- NetworkConnectivityChecker.customUpdateStatus(
- kIsOnline ? ConnectivityResult.none : ConnectivityResult.wifi,
- );
- }
- void setLogSwitch() async {
- final isEnable = !state.isDeviceLogEnable;
- await VnoteDevicePluginPlatform.instance.setLogEnable(isEnable);
- state.isDeviceLogEnable = isEnable;
- }
- void _onNetOnlineChanged(_, bool val) {
- state.isNetOnline = val;
- }
- void detectCamera() async {
- state.cameraList.clear();
- try {
- final _cameras = await availableCameras();
- for (final camera in _cameras) {
- state.cameraList.add(camera.toString());
- }
- } catch (e) {
- state.errorMessage.value = e.toString();
- }
- }
- void openCameraTest() async {
- await Get.to(() => const CameraTest());
- }
- }
|