terminate_restart 1.0.0 copy "terminate_restart: ^1.0.0" to clipboard
terminate_restart: ^1.0.0 copied to clipboard

A robust Flutter plugin for terminating and restarting your app with extensive customization options. Supports both Android and iOS with features like data clearing and state preservation.

๐Ÿ”„ Terminate Restart #

pub package License: MIT likes popularity pub points

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.

๐ŸŒŸ Features #

  • โœจ Two Restart Modes:
    • UI-only restart (recreate activities/views)
    • Full process termination and restart
  • ๐Ÿงน Smart Data Management:
    • Optional data clearing during restart
    • Configurable data preservation options
    • Proper cleanup of app state
  • ๐Ÿ”’ Secure Data Handling:
    • Preserve keychain data
    • Preserve user defaults/shared preferences
    • Clean process termination
  • ๐Ÿ“ฑ Platform Support:
    • โœ… Android
    • โœ… iOS (coming soon)
  • ๐ŸŽจ Rich UI Options:
    • Customizable confirmation dialogs
    • Immediate mode for quick restarts
    • Beautiful default UI
  • โšก Performance:
    • Minimal initialization delay
    • Optimized process handling
    • Clean state management

๐Ÿ“ฆ Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  terminate_restart: ^1.0.0

๐Ÿš€ Usage #

Basic Usage #

import 'package:terminate_restart/terminate_restart.dart';

// Simple UI-only restart
await TerminateRestart.restartApp(
  terminate: false, // false for UI-only restart
);

// Full process termination and restart
await TerminateRestart.restartApp(
  terminate: true, // true for full process termination
);

Advanced Usage with Data Clearing #

// Restart with data clearing
await TerminateRestart.restartApp(
  clearData: true, // Clear app data
  preserveKeychain: true, // Keep sensitive data
  preserveUserDefaults: false, // Clear preferences
  terminate: true, // Full process restart
);

Confirmation Dialog #

// Restart with custom confirmation dialog
await TerminateRestart.restartApp(
  context: context, // Required for dialog
  mode: RestartMode.withConfirmation,
  dialogTitle: 'โœจ Update Ready!',
  dialogMessage: 'Restart now to apply updates?',
  restartNowText: '๐Ÿš€ Restart Now',
  restartLaterText: 'โฐ Later',
  cancelText: 'โŒ Cancel',
);

Error Handling #

try {
  final success = await TerminateRestart.restartApp(
    terminate: true,
    clearData: true,
  );
  
  if (!success) {
    print('Restart cancelled or failed');
  }
} catch (e) {
  print('Error during restart: $e');
}

Complete Example with State Management #

class _MyHomePageState extends State<MyHomePage> {
  // Store persistent data
  late SharedPreferences _prefs;
  int _counter = 0;
  
  @override
  void initState() {
    super.initState();
    _loadCounter();
  }
  
  Future<void> _loadCounter() async {
    _prefs = await SharedPreferences.getInstance();
    setState(() {
      _counter = _prefs.getInt('counter') ?? 0;
    });
  }
  
  Future<void> _incrementCounter() async {
    setState(() {
      _counter++;
    });
    await _prefs.setInt('counter', _counter);
  }
  
  Future<void> _restartApp() async {
    final bool confirmed = await showDialog<bool>(
      context: context,
      builder: (context) => AlertDialog(
        title: Text('Restart App'),
        content: Text('Do you want to clear data and restart?'),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context, false),
            child: Text('Cancel'),
          ),
          TextButton(
            onPressed: () => Navigator.pop(context, true),
            child: Text('Yes, Restart'),
          ),
        ],
      ),
    ) ?? false;
    
    if (confirmed) {
      await TerminateRestart.restartApp(
        clearData: true,
        preserveKeychain: true,
        terminate: true,
      );
    }
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Terminate Restart Demo')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Counter: $_counter'),
            ElevatedButton(
              onPressed: _incrementCounter,
              child: Text('Increment'),
            ),
            ElevatedButton(
              onPressed: _restartApp,
              child: Text('Clear & Restart'),
            ),
          ],
        ),
      ),
    );
  }
}

๐Ÿ“š API Reference #

TerminateRestart.restartApp() #

Main method to restart your app with various options:

Parameter Type Default Description
context BuildContext? null Required for confirmation dialog
mode RestartMode immediate Choose between immediate/confirmation
clearData bool false Whether to clear app data
preserveKeychain bool false Keep keychain data when clearing
preserveUserDefaults bool false Keep user defaults when clearing
terminate bool true Full process termination vs UI refresh
dialogTitle String? null Custom title for confirmation dialog
dialogMessage String? null Custom message for confirmation dialog
restartNowText String? null Custom text for restart now button
restartLaterText String? null Custom text for restart later button
cancelText String? null Custom text for cancel button

Returns Future<bool> indicating success or failure.

๐Ÿ”ง Platform-Specific Details #

Android #

  • Uses Process.killProcess() for clean termination
  • Proper activity stack handling with Intent flags
  • Smart SharedPreferences management
  • Handles all app data directories

iOS (Coming Soon) #

  • Clean process termination
  • State preservation options
  • Keychain data handling
  • User defaults management

๐Ÿค Contributing #

  1. Fork it
  2. Create your feature branch (git checkout -b feature/amazing)
  3. Commit your changes (git commit -am 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing)
  5. Create a Pull Request

๐Ÿ“ License #

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author #

Made with โค๏ธ by Ahmed Sleem


GitHub โ€ข pub.dev โ€ข Issues

22
likes
0
points
307
downloads

Publisher

unverified uploader

Weekly Downloads

A robust Flutter plugin for terminating and restarting your app with extensive customization options. Supports both Android and iOS with features like data clearing and state preservation.

Repository (GitHub)
View/report issues

Topics

#restart #terminate #process-management #app-lifecycle #data-clearing

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on terminate_restart