updateWidget method

void updateWidget(
  1. String widgetId,
  2. String newContent
)

Send specific widget update

Implementation

void updateWidget(String widgetId, String newContent) {
  if (_clients.isEmpty) return;

  final updateMessage = jsonEncode({
    'type': 'widget_update',
    'timestamp': DateTime.now().millisecondsSinceEpoch,
    'widgetId': widgetId,
    'content': newContent,
  });

  _clients.removeWhere((client) {
    try {
      client.add(updateMessage);
      return false;
    } catch (e) {
      print('❌ Failed to send widget update to client: $e');
      return true;
    }
  });

  print('🔥 Widget update sent for ${_clients.length} clients');
}