checkRootAccess static method

Future<void> checkRootAccess()

Implementation

static Future<void> checkRootAccess() async {
  bool rootAccess = false;
  bool checkRootAccess = SpUtil.getBool('checkRootAccess', defValue: false) ?? false;
  if (GetPlatform.isIOS) {
    rootAccess = await FlutterJailbreakDetection.jailbroken;
  } else if (GetPlatform.isAndroid) {
    rootAccess = await RootAccess.requestRootAccess;
  }

  if (rootAccess && !checkRootAccess) {
    SpUtil.putBool('checkRootAccess', true);
    showDialog(
        context: Get.context!,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(
              '安全提示',
              style: TextStyle(color: Colors.black, fontSize: 18.sp),
            ),
            content: Text('检测到您当前设备可能已root,请注意财产安全', style: TextStyle(color: Colors.black, fontSize: 14.sp)),
            actions: <Widget>[
              MaterialButton(
                child: Text('确定', style: TextStyle(color: Colors.blue, fontSize: 14.sp)),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        });
  }
}