init static method

Future init(
  1. VoidCallback callback, {
  2. double? w,
  3. double? h,
  4. int orientation = 0,
  5. bool banRootAccess = true,
})

初始化全局信息 callback 初始化完成回调, SP、BaseConfig、AwesomeExt、PackageUtils、屏幕像素 w 设计稿宽度, h 设计稿高度, orientation 设备方向, 0 竖屏, 1 横屏 banRootAccess是否判断越狱的手机,默认true,禁止越狱的手机使用

Implementation

static Future init(
  VoidCallback callback, {
  double? w,
  double? h,
  int orientation = 0,
  bool banRootAccess = true,
}) async {
  w ??= 375.0;
  h ??= 812.0;

  //确保初始化完成才可用
  WidgetsFlutterBinding.ensureInitialized();
  //sp release初始化30毫秒,debug初始化100毫秒
  await AwesomeExt.init();
  //设计稿大小
  setDesignWHD(w, h);
  //初始化设备 在进入
  await PackageUtils.instance.init();

  callback();
  if (kReleaseMode) {
    debugPrint = (String? message, {int? wrapWidth}) {};
  }
  if (banRootAccess) {
    if (GetPlatform.isIOS) {
      final bool jailbroken = await FlutterJailbreakDetection.jailbroken;
      if (jailbroken) {
        SystemNavigator.pop();
      }
    } else if (GetPlatform.isAndroid) {
      final bool rootAccess = await RootAccess.requestRootAccess;
      if (rootAccess) {
        SystemNavigator.pop();
      }
    }
  }

  if (GetPlatform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。
    const SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    if (orientation == 0) {
      SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    } else if (orientation == 1) {
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.landscapeLeft,
        DeviceOrientation.landscapeRight,
      ]);
    }
  }
}