WebView SDK Manager Reference
API documentation for the WebViewSdkManager class.
Constructor
WebViewSdkManager({
required String environment,
required String basicAuthUser,
required String basicAuthPass,
void Function(String, dynamic)? updateCallback,
})
| Parameter | Type | Description |
|---|---|---|
environment | String | Environment: DEV, UAT, or PRD |
basicAuthUser | String | Username for basic authentication |
basicAuthPass | String | Password for basic authentication |
updateCallback | Function? | Optional callback for WebView events |
Properties
isInitialized
Returns whether the SDK has been initialized.
bool get isInitialized
Methods
init()
Initializes the WebView SDK with client credentials.
Future<void> init({
required String clientId,
required String clientSecret,
required String clientUserId,
required String environment,
required String basicAuthUser,
required String basicAuthPass,
void Function(String, dynamic)? updateCallback,
})
Events
Event Strings
Various event strings are available for the callback function depending on the modules you're using. For comprehensive documentation on MSK Assessment events, please refer to the MSK Integration Guide.
// Example events (see specific integration guides for complete lists):
'START_MSK_ASSESSMENT'
'FINISH_ASSESSMENT_SURVEY'
// ... and more
Example Usage
// Initialize
final webViewSdkManager = WebViewSdkManager(
environment: 'UAT',
basicAuthUser: 'gofa',
basicAuthPass: 'password',
updateCallback: (event, data) {
// Handle events based on your integration
print('Event received: $event');
print('Event data: $data');
// For MSK Assessment events, see the MSK Integration Guide
// at ../msk-integration.md for detailed event handling
},
);
// Register as singleton
GetIt.I.registerSingleton<WebViewSdkManager>(webViewSdkManager);
// Initialize with credentials
await webViewSdkManager.init(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
clientUserId: 'user-id',
environment: 'UAT',
basicAuthUser: 'gofa',
basicAuthPass: 'password',
);
// Check if initialized
if (webViewSdkManager.isInitialized) {
// Ready to use
}
Integration with GetIt
Registration
Register the WebView SDK Manager as a singleton using GetIt:
import 'package:get_it/get_it.dart';
if (!GetIt.I.isRegistered<WebViewSdkManager>()) {
final webViewSdkManager = WebViewSdkManager(
environment: environment,
basicAuthUser: basicAuthUser,
basicAuthPass: basicAuthPass,
updateCallback: webViewSdkUpdateCallback,
);
GetIt.I.registerSingleton<WebViewSdkManager>(webViewSdkManager);
}
Access
Access the registered instance:
final webViewSdkManager = GetIt.I<WebViewSdkManager>();
Unregistration
Unregister when no longer needed:
if (GetIt.I.isRegistered<WebViewSdkManager>()) {
GetIt.I.unregister<WebViewSdkManager>();
}
Error Handling
Common Error Scenarios
| Error Type | Cause | Handling |
|---|---|---|
| Initialization Error | Invalid credentials | Check clientId and clientSecret |
| Network Error | Connection issues | Retry with exponential backoff |
| Authentication Error | Expired tokens | Re-initialize or refresh tokens |
| Configuration Error | Invalid environment | Verify environment settings |
Error Handling Example
try {
await webViewSdkManager.init(
clientId: clientId,
clientSecret: clientSecret,
clientUserId: clientUserId,
environment: environment,
basicAuthUser: basicAuthUser,
basicAuthPass: basicAuthPass,
);
} catch (e) {
if (e is AuthenticationException) {
// Handle authentication errors
showAuthenticationError();
} else if (e is NetworkException) {
// Handle network errors
showNetworkError();
} else {
// Handle other errors
showGenericError(e.toString());
}
}
Best Practices
1. Singleton Pattern
Always use the singleton pattern with GetIt:
// ✅ Correct: Use singleton
if (!GetIt.I.isRegistered<WebViewSdkManager>()) {
GetIt.I.registerSingleton<WebViewSdkManager>(webViewSdkManager);
}
// ❌ Incorrect: Create multiple instances
final manager1 = WebViewSdkManager(...);
final manager2 = WebViewSdkManager(...);
2. Initialization Check
Always check initialization status:
// ✅ Correct: Check before use
if (!webViewSdkManager.isInitialized) {
await webViewSdkManager.init(...);
}
// ❌ Incorrect: Assume it's initialized
webViewSdkManager.someMethod(); // May fail
3. Error Handling
Implement comprehensive error handling:
// ✅ Correct: Handle all error cases
try {
await webViewSdkManager.init(...);
} catch (e) {
handleInitializationError(e);
}
// ❌ Incorrect: No error handling
webViewSdkManager.init(...); // May fail silently
4. Callback Implementation
Implement callback for better user experience:
// ✅ Correct: Provide callback for events
WebViewSdkManager(
updateCallback: (event, data) {
// Handle events appropriately
handleWebViewEvent(event, data);
},
);
// ❌ Incorrect: No callback
WebViewSdkManager(); // Missing important events
Related Documentation
- MSK Integration Guide: Detailed guide for integrating MSK Assessment functionality, including all MSK-specific events and their data structures.