feat: Root checker screen.

This commit is contained in:
Aunali321
2022-08-14 19:33:01 +05:30
parent f3383393ef
commit 6061d900ed
10 changed files with 236 additions and 3 deletions

View File

@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/views/root_checker/root_checker_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/magisk_button.dart';
import 'package:stacked/stacked.dart';
class RootCheckerView extends StatelessWidget {
const RootCheckerView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<RootCheckerViewModel>.reactive(
onModelReady: (model) => model.initialize,
viewModelBuilder: () => RootCheckerViewModel(),
builder: (context, model, child) => Scaffold(
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Text('nonroot'),
const SizedBox(height: 8),
FloatingActionButton(
onPressed: model.navigateToHome,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(48),
),
child: const Icon(
Icons.keyboard_arrow_right,
size: 32,
),
),
],
),
body: Container(
height: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 28.0),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
const SizedBox(height: 120),
I18nText(
'rootCheckerView.widgetTitle',
child: Text(
'',
style: GoogleFonts.jetBrainsMono(
fontSize: 24,
),
),
),
const SizedBox(height: 24),
I18nText(
'rootCheckerView.widgetDescription',
child: Text(
'',
textAlign: TextAlign.center,
style: GoogleFonts.roboto(
fontSize: 17,
letterSpacing: 1.1,
),
),
),
const SizedBox(height: 170),
MagiskButton(
onPressed: () {
model.getMagiskPermissions();
Future.delayed(const Duration(seconds: 5), () {
model.checkRoot();
});
},
),
Text(
"Magisk permission granted: ${model.isRooted.toString()}",
style: GoogleFonts.poppins(),
),
],
),
),
),
);
}
}

View File

@ -0,0 +1,38 @@
import 'package:fluttertoast/fluttertoast.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';
import 'package:root/root.dart';
import 'package:stacked_services/stacked_services.dart';
class RootCheckerViewModel extends BaseViewModel {
final _navigationService = locator<NavigationService>();
bool? isRooted = false;
Future<void> initialize() async {
await checkRoot();
notifyListeners();
}
Future<void> checkRoot() async {
isRooted = await Root.isRooted();
notifyListeners();
}
Future<void> getMagiskPermissions() async {
if (isRooted == true) {
Fluttertoast.showToast(msg: 'Magisk permission already granted!');
}
await Root.exec(cmd: "adb shell su -c exit");
notifyListeners();
}
Future<void> navigateToHome() async {
final prefs = await SharedPreferences.getInstance();
prefs.setBool('showHome', true);
_navigationService.navigateTo(Routes.homeView);
notifyListeners();
}
}

View File

@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/theme.dart';
class MagiskButton extends StatelessWidget {
final Function()? onPressed;
const MagiskButton({
Key? key,
this.onPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: onPressed,
child: CircleAvatar(
radius: 32,
backgroundColor: isDark
? Theme.of(context).colorScheme.secondary
: const Color(0xffCBDFFC),
child: SvgPicture.asset(
'assets/images/magisk.svg',
color: isDark ? Colors.white70 : Colors.grey[900],
height: 50,
width: 50,
),
),
),
const SizedBox(height: 8),
I18nText(
'rootCheckerView.grantPermission',
child: Text(
'',
style: GoogleFonts.poppins(
fontSize: 15,
),
),
),
],
);
}
}