flutter_crash_now 1.0.0
flutter_crash_now: ^1.0.0 copied to clipboard
A Flutter plugin to trigger app crashes for testing crash reporting systems and anti-tampering protection.
import 'package:flutter/material.dart';
import 'package:flutter_crash_now/flutter_crash_now.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Crash Now Demo',
theme: ThemeData(
primarySwatch: Colors.red,
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String _version = 'Unknown';
@override
void initState() {
super.initState();
_loadVersion();
}
void _loadVersion() {
setState(() {
_version = FlutterCrashNow.version;
});
}
void _showCrashConfirmation() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Row(
children: [
Icon(Icons.warning_amber_rounded, color: Colors.orange),
SizedBox(width: 8),
Text('Warning'),
],
),
content: const Text(
'Are you sure you want to trigger app crash?\n\n'
'The app will terminate immediately and cannot be recovered.\n'
'Please ensure all important data is saved.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
// Give user a moment to see the confirmation
Future.delayed(const Duration(milliseconds: 500), () {
FlutterCrashNow.crash();
});
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
child: const Text('Confirm Crash'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Crash Now Demo'),
elevation: 2,
),
body: SingleChildScrollView(
child: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Logo
const Icon(
Icons.bug_report,
size: 100,
color: Colors.red,
),
const SizedBox(height: 32),
// Title
const Text(
'Flutter Crash Now',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
// Version info
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(20),
),
child: Text(
'Version: $_version',
style: TextStyle(
fontSize: 14,
color: Colors.grey[700],
),
),
),
const SizedBox(height: 48),
// Description
const Card(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline, size: 20),
SizedBox(width: 8),
Text(
'Plugin Features',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
SizedBox(height: 12),
Text(
'• Test crash log collection systems\n'
'• Verify crash recovery mechanisms\n'
'• Security protection testing\n'
'• Primarily for development and testing',
style: TextStyle(height: 1.5),
),
],
),
),
),
const SizedBox(height: 48),
// Trigger crash button
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton.icon(
onPressed: _showCrashConfirmation,
icon: const Icon(Icons.error_outline),
label: const Text(
'Trigger App Crash',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(height: 16),
// Warning message
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.orange[50],
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.orange[200]!),
),
child: Row(
children: [
Icon(
Icons.warning_amber_rounded,
size: 20,
color: Colors.orange[700],
),
const SizedBox(width: 8),
Expanded(
child: Text(
'Warning: App will crash immediately after clicking',
style: TextStyle(
fontSize: 12,
color: Colors.orange[900],
),
),
),
],
),
),
],
),
),
),
),
);
}
}