resolveEntries static method

List<Widget> resolveEntries(
  1. List<WidgetEntry> entries, {
  2. ColorScheme? hostColorScheme,
  3. OnWidgetDismiss? onDismiss,
  4. OnWidgetAction? onAction,
  5. String? userId,
  6. WidgetService? analyticsService,
})

Resolve a list of WidgetEntry into Flutter widgets.

Priority for ColorScheme (highest wins):

  1. Per-widget color_palette from agent JSON
  2. hostColorScheme passed by the developer
  3. The ambient Theme from context

When userId and analyticsService are both provided, impressions are tracked automatically on first render and dismiss events are forwarded to the analytics backend in addition to calling onDismiss.

Implementation

static List<Widget> resolveEntries(
  List<WidgetEntry> entries, {
  ColorScheme? hostColorScheme,
  OnWidgetDismiss? onDismiss,
  OnWidgetAction? onAction,
  String? userId,
  WidgetService? analyticsService,
}) {
  final widgets = <Widget>[];

  for (final entry in entries) {
    final entryId = entry.id;
    final child = WidgetRegistry.build(
      entry.type,
      entry.params,
      onAction: onAction != null ? (url) => onAction(entryId, url) : null,
    );
    if (child == null) continue;

    // Per-widget color scheme from agent JSON takes priority,
    // then the host's color scheme passed by the developer.
    final effectiveColorScheme =
        entry.common.colorScheme ?? hostColorScheme;

    Widget wrapped = ResponsiveWidgetWrapper(
      layout: entry.common.layout,
      themeOverride: entry.common.themeOverride,
      colorScheme: effectiveColorScheme,
      child: child,
    );

    if (entry.common.dismissible && onDismiss != null) {
      wrapped = Dismissible(
        key: ValueKey(entryId),
        onDismissed: (_) {
          if (userId != null && analyticsService != null) {
            analyticsService
                .recordInteraction(entryId, userId, action: 'dismiss')
                .ignore();
          }
          onDismiss(entryId);
        },
        child: wrapped,
      );
    }

    // Wrap with impression tracker when analytics is configured.
    if (userId != null && analyticsService != null) {
      wrapped = ImpressionTracker(
        widgetId: entry.id,
        userId: userId,
        service: analyticsService,
        child: wrapped,
      );
    }

    widgets.add(wrapped);
  }

  // Enforce the plan's widget limit. -1 means unlimited, 0 means SDK not
  // yet initialized (no limit applied). Any positive value caps the list.
  final limit = IntyxDynamicWidget.widgetLimit;
  if (limit > 0 && widgets.length > limit) {
    return widgets.sublist(0, limit);
  }

  return widgets;
}