import 'dart:io';

import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'package:base_app/common/common.dart';

class Global {
  //初始化全局信息
  static Future init(VoidCallback callback) async {
    WidgetsFlutterBinding.ensureInitialized();
    await SpUtil.getInstance();
    // 系统初始化配置
    String readFormLocal = SpUtil.getString(BaseConstant.keyReadFormLocal);
    if (readFormLocal == null || readFormLocal == "") {
      // 默认使用网络
      SpUtil.putString(BaseConstant.keyReadFormLocal, "false");
    }
    // 临时测试用，重置url
    // SpUtil.putString(Constant.key_url, BaseConstant.serverAddress); // 请求ip和端口

    String baseUrl = SpUtil.getString(Constant.key_url);
    if (baseUrl == null || baseUrl == "") {
      SpUtil.putString(Constant.key_url, BaseConstant.serverAddress); // 请求ip和端口
    }

    // 设置强制竖屏
    if (Platform.isAndroid) {
      // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
      SystemUiOverlayStyle systemUiOverlayStyle =
          SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      // 强制竖屏
      SystemChrome.setPreferredOrientations(
          [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    }
    callback();
  }
}

class Router {
  static GlobalKey<NavigatorState> navigatorKey = GlobalKey();
}
