terminate_restart 1.0.5
terminate_restart: ^1.0.5 copied to clipboard
A Flutter plugin for app termination and restart with data clearing options.
๐ Terminate Restart #
A robust Flutter plugin for terminating and restarting your app with extensive customization options. Perfect for implementing dynamic updates, clearing app state, or refreshing your app's UI.
๐ฑ Demo #
Plugin in Action
Clean & Simple Interface
The demo showcases:
- ๐ UI-only restart for quick refreshes
- ๐ Full app termination and restart
- ๐งน Data clearing with preservation options
- ๐ Customizable confirmation dialogs
- โก Smooth transitions and animations
๐ Features #
-
โจ Two Restart Modes:
- UI-only Restart: (~200ms)
- Recreates activities/views while maintaining connections
- Perfect for theme changes, language switches
- Preserves network connections and background tasks
- Faster execution with minimal disruption
- Full Process Restart: (~800ms)
- Complete app termination and restart
- Ideal for updates, security-related changes
- Cleans up all resources and states
- Ensures fresh start with no residual state
- UI-only Restart: (~200ms)
-
๐งน Smart Data Management:
- Configurable data clearing during restart
- Granular control over data preservation
- Secure handling of sensitive information
-
๐ Security Features:
- Optional keychain data preservation
- Secure user defaults handling
- Clean process termination
-
๐ฑ Platform Support:
- โ Android: Full support with activity recreation
- โ iOS: Compliant with App Store guidelines
-
๐ซ User Experience:
- Built-in confirmation dialogs
- Customizable messages and buttons
- Smooth transitions and animations
๐ฆ Installation #
dependencies:
terminate_restart: ^1.0.5
Permissions #
No special permissions are required for either Android or iOS! The plugin uses only standard platform APIs:
Android
- No additional permissions needed in AndroidManifest.xml
- Uses standard Activity lifecycle methods
- No protected features accessed
iOS
- No special entitlements needed in Info.plist
- No additional capabilities required
- Uses standard UIKit methods
๐ Getting Started #
- Initialize the Plugin
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Initialize with default settings
TerminateRestart.instance.initialize();
runApp(MyApp());
}
- Basic Usage
// UI-only restart (fast, maintains connections)
await TerminateRestart.instance.restartApp(
options: const TerminateRestartOptions(
terminate: false,
),
);
// Full app restart (clean slate)
await TerminateRestart.instance.restartApp(
options: const TerminateRestartOptions(
terminate: true,
),
);
Advanced Usage #
// Initialize with custom root reset handler
TerminateRestart.instance.initialize(
onRootReset: () {
// Custom navigation reset logic
Navigator.of(context).pushNamedAndRemoveUntil('/home', (_) => false);
},
);
// Handle back navigation (Android)
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
// Your custom back navigation logic
return true;
},
child: Scaffold(
// Your app content
),
);
}
๐ฑ Platform-Specific Notes #
Android #
- Uses
Process.killProcess()
for clean termination - Handles activity recreation properly
- Manages app data clearing through proper Android APIs
- Supports custom intent flags
- Handles task stack management
iOS #
- Implements clean process termination
- Handles UserDefaults and Keychain data preservation
- Manages view controller recreation for UI-only restarts
- Supports background task completion
- Handles state restoration
๐ Common Use Cases #
-
After Dynamic Updates
// After downloading new assets/code await TerminateRestart.instance.restartApp( terminate: true, mode: RestartMode.withConfirmation, dialogTitle: 'Update Ready', dialogMessage: 'Restart to apply updates?', );
-
Clearing Cache
// Clear app data but preserve important settings await TerminateRestart.instance.restartApp( terminate: true, clearData: true, preserveKeychain: true, preserveUserDefaults: true, );
-
Quick UI Refresh
// Refresh UI without full restart await TerminateRestart.instance.restartApp( terminate: false, );
๐ Performance Metrics #
Operation | Average Time |
---|---|
UI-only Restart | ~300ms |
Full Termination | ~800ms |
Data Clearing | ~200ms |
With Dialog | +100ms |
๐ Security Considerations #
-
Sensitive Data
- Use
preserveKeychain
for credentials - Clear data on logout
- Handle biometric authentication state
- Use
-
State Management
- Clear sensitive state before restart
- Handle authentication tokens properly
- Manage secure storage access
-
Platform Security
- Proper permission handling
- Secure data clearing
- Protected file access
๐ค Contributing #
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing
) - Commit your changes (
git commit -am 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing
) - Open a Pull Request
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments #
Special thanks to:
- The Flutter team for the amazing framework
- All contributors who helped improve this plugin
- The community for valuable feedback and suggestions
๐ Support #
If you have any questions or need help, you can:
- Open an issue
- Check our example for more usage examples
- Read our API documentation
๐ Complete Example #
Check out our example app for a full demonstration of all features, including:
- Basic UI/Process restart
- Data clearing with preservation options
- Custom confirmation dialogs
- Error handling
- State management
- Platform-specific features
๐ฅ Demo #
Quick Preview #
Example Screenshots #
Note: For a video demonstration of the plugin in action, visit our YouTube channel.
๐ง Platform-Specific Details #
Android Implementation #
The Android implementation uses a combination of techniques to ensure reliable app restart:
// Activity recreation (UI-only restart)
currentActivity.recreate()
// Full process termination
Process.killProcess(Process.myPid())
exitProcess(0)
// Smart Intent handling
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
iOS Implementation #
The iOS implementation provides:
- Clean process termination
- State preservation options
- Keychain data handling
- User defaults management
๐จโ๐ป Author #
Made with โค๏ธ by Ahmed Sleem GitHub โข pub.dev โข LinkedIn
๐ง Configuration Options #
Core Parameters #
Parameter | Type | Default | Description |
---|---|---|---|
terminate |
bool |
true |
Full termination vs UI-only restart |
clearData |
bool |
false |
Clear app data during restart |
preserveKeychain |
bool |
false |
Keep keychain data when clearing |
preserveUserDefaults |
bool |
false |
Keep user defaults when clearing |
Performance Considerations #
-
UI-only Restart (~200ms):
- Maintains network connections
- Preserves background tasks
- Ideal for UI updates
-
Full Restart (~800ms):
- Terminates all processes
- Cleans up resources
- Required for security-related changes
๐ฏ Real-World Examples #
Theme Switching #
class ThemeManager {
Future<void> toggleTheme() async {
// Update theme in your state management solution
// Example using Provider (implement based on your state management):
// Provider.of<ThemeProvider>(context, listen: false).toggleTheme();
await TerminateRestart.instance.restartApp(
options: const TerminateRestartOptions(
terminate: false, // UI-only restart is sufficient
),
);
}
}
App Update #
class UpdateManager {
Future<void> applyUpdate() async {
try {
// Show confirmation with custom message
final context = // Get valid context from your widget tree
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Update Ready'),
content: Text('Restart to apply updates?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text('Later'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: Text('Restart Now'),
),
],
),
);
if (confirmed == true) {
await TerminateRestart.instance.restartApp(
options: const TerminateRestartOptions(
terminate: true, // Full restart for updates
clearData: false,
),
);
}
} catch (e) {
print('Update failed: $e');
}
}
}
Custom Navigation Reset #
// Initialize with custom navigation handling
TerminateRestart.instance.initialize(
onRootReset: () {
// Example: Reset to home screen and clear navigation stack
// Note: Ensure you have a valid context when accessing Navigator
Navigator.of(context).pushNamedAndRemoveUntil(
'/home',
(_) => false, // Remove all previous routes
);
},
);
โ ๏ธ Platform Considerations #
iOS #
- Complies with App Store guidelines regarding app termination
- Uses approved methods for activity recreation
- Handles state preservation according to iOS lifecycle
Android #
- Implements proper activity recreation
- Handles back navigation appropriately
- Manages process termination safely
๐ Security Best Practices #
-
Data Clearing
- Use
clearData: true
for security-sensitive operations - Enable
preserveKeychain
to retain critical credentials - Consider
preserveUserDefaults
for app settings
- Use
-
State Management
- Clear sensitive data before restart
- Implement proper authentication state handling
- Use secure storage for critical information
๐ฅ Contributing #
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
๐ Acknowledgments #
Special thanks to:
- Our beta testers and early adopters
- The Flutter community for valuable feedback
- Contributors who helped improve the package
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.