apply method

  1. @override
List<String> apply(
  1. Map<String, int> interactionCounts
)
override

Apply the rule to the analysis result Returns a list of widgets in their recommended order

Implementation

@override
List<String> apply(Map<String, int> interactionCounts) {
  // Get widgets that are in the fixed order list and in the interaction counts
  final fixedWidgets = fixedOrderWidgets
      .where((id) => interactionCounts.containsKey(id))
      .toList();

  // Get widgets that are not in the fixed order list
  final otherWidgets = interactionCounts.keys
      .where((id) => !fixedOrderWidgets.contains(id))
      .toList();

  // Sort the other widgets by count
  otherWidgets.sort((a, b) =>
      (interactionCounts[b] ?? 0).compareTo(interactionCounts[a] ?? 0));

  // Return fixed widgets first, then the rest
  return [...fixedWidgets, ...otherWidgets];
}