Kill Switch
A Flutter Package That Provides A kill Switch Functionality For Your App Using Firebase Firestore. This Package Allows App Owners To Remotely Disable Their App For Users With A Sleek, Professional Interface.
✨ Features
- 🎛️ Professional Kill Switch UI - Dark themed interface with large Cupertino-style switch
- 🔥 Firebase Integration - Real-time monitoring using Cloud Firestore
- 🚫 Non-Dismissible App Blocking - Complete app blocking when kill switch is active
- 📱 Cross-Platform Support - Works on both iOS and Android
- ⚡ Real-time Updates - Instant kill switch activation/deactivation across all user devices
- 🎯 Instant Dialog Management - Dialogs appear and disappear instantly without app restart
- 📱 Example App Included - Complete demo app showing proper implementation
- 📚 Comprehensive Documentation - Full API documentation with Flutter-style comments
📋 Prerequisites
Before using this package, ensure you have:
1. Firebase Setup
Your Flutter app must have Firebase configured and initialized:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
2. Firestore Database
- Cloud Firestore must be enabled in your Firebase project
- Set up appropriate Firestore security rules
3. Required Dependencies
Add these to your app's pubspec.yaml
:
dependencies:
firebase_core: ^2.17.0
cloud_firestore: ^4.13.0
flutter_kill_switch: ^1.0.0
🚀 Installation
Add this to your package's pubspec.yaml
file:
flutter pub add kill_switch
Or manually add to your pubspec.yaml
:
dependencies:
kill_switch: ^1.0.0
Then run:
flutter pub get
📖 Usage
Step 1: Import the Package
import 'package:kill_switch/kill_switch.dart';
Step 2: Wrap Your Main App
Wrap your main app widget with KillSwitchWrapper
to enable monitoring:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
home: KillSwitchWrapper(
child: YourMainScreen(), // Your app's main screen
),
);
}
}
Step 3: Navigate to Kill Switch Screen
Replace your admin/settings navigation with:
// Instead of navigating to your custom admin screen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FlutterKillSwitch(), // Use the package screen
),
);
Complete Example
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:kill_switch_flutter/kill_switch.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Kill Switch Demo',
theme: ThemeData(
brightness: Brightness.dark,
scaffoldBackgroundColor: const Color(0xFF2C2C2E),
colorScheme: const ColorScheme.dark(
primary: Colors.red,
secondary: Colors.white,
surface: Color(0xFF2C2C2E),
),
),
home: KillSwitchWrapper(
child: MainDemoScreen(),
),
);
}
}
class MainDemoScreen extends StatelessWidget {
const MainDemoScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF2C2C2E),
body: Center(
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
const Text(
'KILL SWITCH DEMO',
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
const Text(
'This screen demonstrates the Kill Switch functionality.\n\nWhen enabled, a dialog will appear instantly.',
style: TextStyle(
color: Colors.white70,
fontSize: 16,
height: 1.5,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 60),
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const FlutterKillSwitch(),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 0,
),
child: const Text(
'Admin Panel - Toggle Kill Switch',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(height: 30),
const Text(
'Try enabling the kill switch in Admin Panel\nand return here to see the dialog.',
style: TextStyle(
color: Colors.white60,
fontSize: 14,
),
textAlign: TextAlign.center,
),
const Spacer(),
],
),
),
),
);
}
}
🎮 Running the Example
The package includes a complete example app. To run it:
cd example
flutter pub get
flutter run
The example demonstrates:
- Proper
KillSwitchWrapper
implementation - Navigation to admin panel
- Real-time dialog showing/hiding
- Modern dark theme design
🔧 How It Works
Kill Switch Activation Process
- Admin navigates to kill switch screen
- Toggle switch to enable kill switch
- Confirmation dialog to confirm what you are doing
- Kill switch activates and updates Firebase only after confirmation
- All user devices receive the update instantly
- App blocking dialog appears for all users immediately
- Users must close the app
Real-time Dialog Management
- Instant Show: Dialog appears immediately when kill switch becomes
true
- Instant Hide: Dialog disappears immediately when kill switch becomes
false
- No Restart Required: All changes happen in real-time without app restart
- Cross-device Sync: Changes sync instantly across all devices
Firebase Firestore Structure
The package creates this structure in your Firestore database:
📁 IAmNothing/
📁 NothingInsideMe/
📁 WhyAreYouFollowingThisCollection/
📄 here/
✅ FlutterKillSwitch: boolean
📅 lastUpdated: timestamp
Don't worry about the funny collection names - they're intentionally obscure for security! 🔒
🎨 Screenshots
Kill Switch Screen
- Dark themed interface matching modern design standards
- Large, responsive Cupertino switch
- Clear warning messages
Confirmation Dialog
- Custom keyboard with capital letters only
- Real-time text validation with color feedback
- Secure confirmation process
App Blocking Dialog
- Professional blocking interface
- Non-dismissible dialog (back button disabled)
- Clean "Close App" functionality
🔒 Security Features
- Custom Collection Path: Uses obscure Firestore paths
- Confirmation Required: Must type specific text to enable
- Real-time Monitoring: Instant activation across devices
- Non-Dismissible: Users cannot bypass the kill switch
- Automatic Closure: Forces app termination when active
⚠️ Important Notes
- Firebase Required: This package requires active Firebase/Firestore setup
- Internet Connection: Kill switch requires internet to function
- Admin Access: Only admins should have access to the kill switch screen
- Testing: Test thoroughly in development before production use
- Backup Plan: Have alternative communication channels with users
🐛 Troubleshooting
Common Issues
Firebase not initialized:
// Ensure Firebase is initialized before runApp()
await Firebase.initializeApp();
Firestore permissions:
// Update Firestore rules to allow read/write
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true; // Adjust as needed
}
}
}
Kill switch not activating:
- Check internet connection
- Verify Firestore setup
- Ensure KillSwitchWrapper is properly implemented
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Author
Muzamil Ghafoor
- GitHub: @muzzammil763
- Email: deadbase763@gmail.com
🙏 Acknowledgments
- Flutter team for the amazing framework
- Firebase team for the backend services
- Open source community for inspiration
📚 API Documentation
FlutterKillSwitch Widget
The main admin interface for controlling the kill switch.
const FlutterKillSwitch({Key? key})
Features:
- Real-time Firebase Firestore synchronization
- Confirmation dialog with custom keyboard
- Dark theme design with improved layout
- Error handling with debug prints
- Responsive UI design
KillSwitchWrapper Widget
Wraps your app to monitor kill switch state and show blocking dialogs.
const KillSwitchWrapper({
Key? key,
required Widget child,
})
Parameters:
child
(required): The widget to display when kill switch is inactive
Features:
- Real-time Firestore monitoring
- Instant dialog show/hide without app restart
- Non-dismissible blocking dialog
- Automatic app termination functionality
📊 Changelog
0.0.2
- 2025-01-XX
- NEW: Instant dialog showing/hiding without app restart
- NEW: Comprehensive API documentation with Flutter-style comments
- NEW: Complete example app with proper implementation guide
- IMPROVED: Kill switch only updates database after user confirmation
- IMPROVED: Enhanced UI design with better spacing and typography
- IMPROVED: Replaced SnackBar notifications with debug prints
- FIXED: Real-time dialog management race conditions
- FIXED: Dialog hiding logic for better state management
0.0.1
- 2024-12-XX
- Initial release
- Kill switch functionality
- Firebase integration
- Custom confirmation system
- App blocking feature
Made with ❤️ by Muzamil Ghafoor