safe_device 1.1.8 safe_device: ^1.1.8 copied to clipboard
With the Flutter safe_device package, you can easily implement security steps such as Jailbroken, root, emulator and fake location detection.
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:safe_device/safe_device.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool isJailBroken = false;
bool isMockLocation = false;
bool isRealDevice = true;
bool isOnExternalStorage = false;
bool isSafeDevice = false;
bool isDevelopmentModeEnable = false;
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
await Permission.location.request();
if (await Permission.location.isPermanentlyDenied) {
openAppSettings();
}
if (!mounted) return;
try {
isJailBroken = await SafeDevice.isJailBroken;
isMockLocation = await SafeDevice.isMockLocation;
isRealDevice = await SafeDevice.isRealDevice;
isOnExternalStorage = await SafeDevice.isOnExternalStorage;
isSafeDevice = await SafeDevice.isSafeDevice;
isDevelopmentModeEnable = await SafeDevice.isDevelopmentModeEnable;
setState(() {});
} catch (error) {
print(error);
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Device Safe check'),
),
body: Center(
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isJailBroken():'),
SizedBox(
width: 8,
),
Text(
'${isJailBroken ? "Yes" : "No"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isMockLocation():'),
SizedBox(
width: 8,
),
Text(
'${isMockLocation ? "Yes" : "No"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isRealDevice():'),
SizedBox(
width: 8,
),
Text(
'${isRealDevice ? "Yes" : "No"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isOnExternalStorage():'),
SizedBox(
width: 8,
),
Text(
'${isOnExternalStorage ? "Yes" : "No"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isSafeDevice():'),
SizedBox(
width: 8,
),
Text(
'${isSafeDevice ? "Yes" : "False"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('isDevelopmentModeEnable():'),
SizedBox(
width: 8,
),
Text(
'${isDevelopmentModeEnable ? "Yes" : "False"}',
style: TextStyle(fontWeight: FontWeight.w600),
),
],
),
],
),
),
),
),
),
);
}
}