safety_net_flutter 1.0.0
safety_net_flutter: ^1.0.0 copied to clipboard
Flutter plugin wrapping SafetyNet (iOS) and SafetyNetAndroid for report-only root/jailbreak/tamper/debugger detection on both platforms.
import 'package:flutter/material.dart';
import 'package:safety_net_flutter/safety_net_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
SafetyNetCheckResult? _result;
String? _error;
@override
void initState() {
super.initState();
runCheck();
}
Future<void> runCheck() async {
SafetyNetCheckResult result;
try {
result = await SafetyNetFlutter.check();
} catch (e) {
if (!mounted) return;
setState(() => _error = e.toString());
return;
}
if (!mounted) return;
setState(() {
_result = result;
_error = null;
});
}
@override
Widget build(BuildContext context) {
final result = _result;
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('SafetyNet example')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (_error != null) Text('Error: $_error'),
if (result != null) ...[
Text(
result.isCompromised
? 'Compromised device detected'
: 'Device looks clean',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 12),
if (result.reasons.isNotEmpty)
Text('Reasons: ${result.reasons.join(', ')}'),
],
const SizedBox(height: 24),
ElevatedButton(
onPressed: runCheck,
child: const Text('Run check again'),
),
],
),
),
),
),
);
}
}