Event & Error Handling
The Lune SDK provides optional callback hooks so your Flutter app can listen for events, errors, and status updates. These callbacks are useful for:
- Debugging: See raw SDK events in your console during development.
- Error Monitoring: Log failures to your app's tracking system (like Sentry or Firebase Crashlytics).
- User Feedback: Show a toast or dialog when something goes wrong or a background action succeeds.
Implementation
You can register any of these callbacks after creating the lunePlugin instance, typically during your app's setup phase.
Example: Registering Callbacks
// General logging for debugging SDK lifecycle events
await lunePlugin.setLoggingCallback((event) {
print('Lune Event: $event');
});
// For logging raw error objects to a monitoring service
await lunePlugin.setErrorLoggerCallback((error) {
print('Lune Error: $error');
// Example: myErrorTracker.log(error);
});
// For showing user-facing error messages
await lunePlugin.setErrorNotifierCallback((errorMessage) {
print('Lune Error Notification: $errorMessage');
// Example: showSnackBar(context, errorMessage);
});
// For confirming a background action was successful
await lunePlugin.setSuccessNotifierCallback((successMessage) {
print('Lune Success: $successMessage');
// Example: showSnackBar(context, successMessage);
});
Callback Descriptions
| Callback | Description | Use Case |
|---|---|---|
setLoggingCallback | Logs detailed SDK lifecycle and state events, like view loaded or request sent. | Debugging |
setErrorLoggerCallback | Catches raw error objects for technical debugging and reporting to error monitoring services. | Error Reporting |
setErrorNotifierCallback | Fires with a user-friendly string when the user should be notified about an error (e.g., “Session expired”). | User-facing Errors |
setSuccessNotifierCallback | Fires with a user-friendly string when a background action completes successfully (e.g., “Session was refreshed.”). | User-facing Success |