postSecureStorageUpdateToDevTools function
Posts a specific Flutter Secure Storage key-value update to the DevTools extension.
This function is used to send individual key-value changes instead of all data.
Args:
key: The storage key that was changed.
value: The new value (can be null for deletions).
operation: The type of operation ('set', 'delete', 'clear').
Example:
import 'package:flutter_secure_storage_devtool/flutter_secure_storage_devtool.dart';
// When a key is updated
postSecureStorageUpdateToDevTools('user_token', 'new_token_value', 'set');
// When a key is deleted
postSecureStorageUpdateToDevTools('user_token', null, 'delete');
Implementation
Future<void> postSecureStorageUpdateToDevTools(
String key,
String? value,
String operation,
) async {
if (!kDebugMode) return;
try {
// Get device information using device_info_plus
final deviceInfo = await getDeviceInfo();
final messageData = {
'key': key,
'value': value,
'operation': operation, // 'set', 'delete', 'clear'
'deviceId': deviceInfo['deviceId'],
'deviceName': deviceInfo['deviceName'],
'timestamp': DateTime.now().millisecondsSinceEpoch,
};
// Post the update event
developer.postEvent(secureStorageUpdateEventKind, messageData);
} catch (e) {
// Error handling without logging
}
}