logInteractionEvent method
Log an interaction event
Implementation
@override
Future<bool> logInteractionEvent(InteractionEvent event) async {
await _ensureInitialized();
// Get existing events for this widget
List<InteractionEvent> events = await getInteractionEvents(event.widgetId);
// Add the new event
events.add(event);
// Save the updated list
final jsonStrings = events.map((e) => jsonEncode(e.toJson())).toList();
final result = await _prefs.setStringList(
'$_interactionEventPrefix${event.widgetId}',
jsonStrings,
);
// Update the list of all widget IDs with events
Set<String> allWidgetIds = Set.from(
_prefs.getStringList('${_interactionEventPrefix}all_widget_ids') ?? []);
allWidgetIds.add(event.widgetId);
await _prefs.setStringList(
'${_interactionEventPrefix}all_widget_ids',
allWidgetIds.toList(),
);
return result;
}