root 插件

一个 Flutter 插件,用于检查 Android 设备 Root 状态并在 Android(仅限)中运行 shell 命令。

此插件基于 Topjohnwu libsu 和 Stericson Root Tools。

root-plugin

用法

要使用此插件,请在您的 pubspec.yaml 文件中添加 root 作为 依赖项

 root: ^2.0.1

导入它

import 'package:root/root.dart';

声明一个异步方法来检查 root 状态

bool _status = false;

 Future<void> checkRoot() async {
    bool result = await Root.isRooted();
    setState(() {
      _status = result;
    });
  }
  
 later you can use _status in your code to let app know the root status. 
 

声明一个异步方法来运行 shell 命令

仅对短时间进程使用此函数,不要用于长时间进程,否则应用程序可能会崩溃
String _result;

 Future<void> setCommand() async {
    String res = await Root.exec(cmd: "cat /proc/version");
    setState(() {
      _result = res;
    });
  }
  
  later you can use the _result in your code to let know the output of the given shell command.
 

GitHub

https://github.com/gokul1630/root