close method
Closes the instance. This method should be called when the instance is no longer needed. Once close is called, the instance can no longer be used.
Implementation
@override
Future<void> close() async {
// Clean up all stream subscriptions and services
// Use try-catch for each to ensure all cleanup happens even if one fails
try {
await connectionCheckerSubscription?.cancel();
} catch (e) {
loge(e, 'Error canceling connection checker subscription');
}
try {
await versionUpdateSubscription?.cancel();
} catch (e) {
loge(e, 'Error canceling version update subscription');
}
try {
await lifecycleSubscription?.cancel();
} catch (e) {
loge(e, 'Error canceling lifecycle subscription');
}
try {
await notificationBadgeSubscription?.cancel();
} catch (e) {
loge(e, 'Error canceling notification badge subscription');
}
try {
connectionChecker?.dispose();
} catch (e) {
loge(e, 'Error disposing connection checker');
}
try {
AppVersionUpdateService().dispose();
} catch (e) {
loge(e, 'Error disposing AppVersionUpdateService');
}
try {
AppLifecycleService().dispose();
} catch (e) {
loge(e, 'Error disposing AppLifecycleService');
}
// Always call super.close() even if cleanup fails
return super.close();
}