global.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
  6. import 'package:vnoteapp/architecture/utils/prompt_box.dart';
  7. import 'package:vnoteapp/managers/index.dart';
  8. import 'package:vnoteapp/rpc.dart';
  9. import 'package:vnoteapp/store/store.dart';
  10. import 'package:fis_common/logger/logger.dart';
  11. abstract class Global {
  12. static Future<void> init() async {
  13. logger.i("Global init start...");
  14. // 锁定横屏
  15. await SystemChrome.setPreferredOrientations([
  16. DeviceOrientation.landscapeLeft,
  17. DeviceOrientation.landscapeRight,
  18. ]);
  19. // SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
  20. SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
  21. SystemChrome.setSystemUIChangeCallback((systemOverlaysAreVisible) async {
  22. await Future.delayed(const Duration(seconds: 1));
  23. SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
  24. });
  25. SystemChrome.setSystemUIOverlayStyle(
  26. const SystemUiOverlayStyle(
  27. statusBarColor: Colors.transparent,
  28. statusBarIconBrightness: Brightness.light,
  29. ),
  30. );
  31. // SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
  32. // 日志
  33. if (kReleaseMode) {
  34. // 生产环境
  35. Get.isLogEnable = false;
  36. } else {
  37. // debug/profile 环境
  38. logger.setMinimumLevel(LogLevel.Degbug);
  39. }
  40. await logger.init();
  41. // Loading工具
  42. PromptBox.init();
  43. // 状态
  44. await Store.init();
  45. _initRpc();
  46. /// 全局管理器中心
  47. ManagerCenter.load();
  48. /// 设备测量插件初始化
  49. await VnoteDevicePluginPlatform.instance.init();
  50. logger.i("Global init finish...");
  51. }
  52. static void _initRpc() {
  53. _updateRpcHostPath("http://192.168.6.80:8400");
  54. }
  55. static void _updateRpcHostPath(String hostPath) {
  56. final uri = Uri.parse(hostPath);
  57. rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
  58. rpc.clearCache();
  59. }
  60. }