lifecycle_guard 1.0.1
lifecycle_guard: ^1.0.1 copied to clipboard
A bulletproof Flutter plugin for mission-critical background execution.
๐ก๏ธ lifecycle_guard #
The bulletproof Flutter plugin for mission-critical background execution.
Stop losing data when Android or iOS aggressively kills your app.
lifecycle_guard ensures your background tasks survive termination, system reboots, and battery optimizations โ guaranteed.
๐ฌ Demo #
Watch lifecycle_guard in action: App swipe โ Background survival โ Task completion.
โจ Features #
| Feature | Description |
|---|---|
| ๐ก๏ธ Isolate Protection | Boots a lightweight secondary engine so your task never shares the UI thread fate |
| ๐ค Android 15+ Ready | Fully compliant with new foregroundServiceType: dataSync requirements |
| ๐ iOS Compatible | Bridges to Apple's native background task scheduler |
| ๐ก Zero Data Loss | Tasks continue even when users swipe the app away |
| โก 30-Second Setup | One-line API โ no complex native configuration needed |
| ๐ User-Safe | No auto-execution, no hidden scripts, everything is user-triggered |
๐ Quick Start #
Installation #
Add to your pubspec.yaml:
dependencies:
lifecycle_guard: ^1.0.0
โ๏ธ Platform-Specific Setup #
For production use, you must configure the native layer for each platform. Click below for detailed guides:
| Platform | Setup Guide | Key Requirements |
|---|---|---|
| Android | Android Guide | Manifest Service, Notification Permissions |
| iOS | iOS Guide | Background Modes, Task Identifiers |
| Common | Interface Docs | Internal Contract Details |
๐ก Usage #
import 'package:lifecycle_guard/lifecycle_guard.dart';
// Trigger a mission-critical background task
await LifecycleGuard.runSecureTask(
id: "sync_user_data",
payload: {
"userId": "12345",
"retry": true,
"timestamp": DateTime.now().toIso8601String(),
},
);
๐ง How It Works #
graph TD
subgraph Flutter_Layer ["Flutter App (UI Thread)"]
A[LifecycleGuard.runSecureTask]
end
subgraph Native_Bridge ["MethodChannel Bridge"]
B{Platform Check}
end
subgraph Native_Layer ["Native Protection Layer"]
C[Android: LifecycleService<br/><i>Foreground + dataSync</i>]
D[iOS: BGTaskScheduler<br/><i>BGProcessingTask</i>]
end
A --> B
B -- Android --> C
B -- iOS --> D
subgraph Results ["Survival Benefits"]
E[โ
App Swipe Survival]
F[โ
Doze Mode Protection]
G[โ
Battery Saver Compliance]
end
C --> Results
D --> Results
style Flutter_Layer fill:#02569B,color:#fff,stroke:#fff
style Native_Layer fill:#2E7D32,color:#fff,stroke:#fff
style Native_Bridge fill:#333,color:#fff
style Results fill:#1b1f23,color:#3fb950,stroke:#3fb950
๐ License #
BSD 3-Clause License โ see LICENSE for details.
Built with โค๏ธ by Crealify ยท Open to collaborate ยท PRs welcome