mediaRuleSetting function

int? mediaRuleSetting(
  1. List<MediaRule> rules,
  2. List<String> path,
  3. double width,
  4. double? height,
  5. Breakpoints breakpoints,
)

The index of the last rule of rules holding on a screen width × height whose patch sets the field at path (["layout", "width"]), or null when none does (the node's own value applies).

Implementation

int? mediaRuleSetting(List<MediaRule> rules, List<String> path, double width, double? height, Breakpoints breakpoints) {
  int? out;
  for (var i = 0; i < rules.length; i++) {
    if (!rules[i].holds(width, height, breakpoints)) continue;
    Object? v = rules[i].patch;
    var found = true;
    for (final k in path) {
      if (v is Map && v.containsKey(k)) {
        v = v[k];
      } else {
        found = false;
        break;
      }
    }
    if (found) out = i;
  }
  return out;
}