import 'package:fis_measure/process/workspace/measure_3d_view_controller.dart';
import 'package:fis_measure/process/workspace/measure_data_controller.dart';
import 'package:flutter/services.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/pages/measure/helpers/measureData_helper.dart';
import 'package:get/get.dart';

import 'index.dart';
import 'package:fis_ui/index.dart';

///测量主界面控制器
class MeasureHomeController extends GetxController {
  MeasureHomeController();

  ///测量主界面状态
  final state = MeasurehomeState();

  /// 测量数据【测量项】【注释项】...
  final measureData = Get.put(
    MeasureDataController(
      MeasureDataHelper.saveImage,
    ),
  );

  /// Carotid :  在此注册 webview 控制器
  final measure3DViewController = Get.put(Measure3DViewController());

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    if (kIsMobile) {
      setPreferredOrientations();
    }
    _initDatas();
    super.onInit();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    super.dispose();
  }

  ///初始化数据
  void _initDatas() async {
    var parameters = router.getParams(NavIds.HOME) ?? {};
    if (parameters.keys.contains('token')) {
      Store.user.setToken(parameters['token'] ?? "");
    }
  }

  void setPreferredOrientations() {
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  }
}
