show method
Show a toastr notification with the given configuration and context
Implementation
void show(ToastrConfig config, BuildContext context) {
// Get overlay from the provided context
final overlay = Overlay.of(context);
// Security validations
if (!ToastrValidator.isValidConfig(config)) {
ToastrValidator.logSecurityEvent(
'INVALID_CONFIG',
'Configuration failed validation',
);
throw ArgumentError('Invalid toastr configuration');
}
// Rate limiting check
if (_shouldThrottleNotifications()) {
ToastrValidator.logSecurityEvent('RATE_LIMIT', 'Too many notifications');
return;
}
// Limit active notifications for security
if (_activeToastrs.length >= ToastrSecurityConfig.maxActiveNotifications) {
ToastrValidator.logSecurityEvent(
'MAX_NOTIFICATIONS',
'Maximum active notifications reached',
);
// Remove oldest notification
_removeOldestToastr();
}
// Sanitize the configuration
final secureConfig = _sanitizeConfig(config);
// Check for duplicates
if (secureConfig.preventDuplicates &&
_duplicateKeys.contains(secureConfig.key)) {
return;
}
final toastId = DateTime.now().millisecondsSinceEpoch.toString();
late OverlayEntry overlayEntry;
overlayEntry = OverlayEntry(
builder: (overlayContext) => _buildPositionedToastr(
secureConfig,
() => _removeToastr(toastId),
context,
),
);
_activeToastrs[toastId] = overlayEntry;
if (secureConfig.preventDuplicates) {
_duplicateKeys.add(secureConfig.key);
}
overlay.insert(overlayEntry);
_notificationCount++;
// Auto-remove after duration
Future.delayed(secureConfig.duration, () {
_removeToastr(toastId);
});
}