valueByTier<T> method

T valueByTier<T>({
  1. T? xxs,
  2. T? xs,
  3. T? sm,
  4. T? md,
  5. T? lg,
  6. T? xl,
  7. T? xxl,
})

returns a specific value according to the current ScreenTier or the next lower value if omitted

Implementation

T valueByTier<T>({
  T? xxs,
  T? xs,
  T? sm,
  T? md,
  T? lg,
  T? xl,
  T? xxl,
}) {
  if ((xxs ?? xs ?? sm ?? md ?? lg ?? xl ?? xxl) == null) {
    throw ArgumentError("You need to provide at least one value (xxs, xs, sm, md, lg, xl, xxl)");
  }
  switch (screenTier) {
    case ScreenTier.xxs:
      return (xxs ?? xs ?? sm ?? md ?? lg ?? xl ?? xxl) as T;
    case ScreenTier.xs:
      return (xs ?? xxs ?? sm ?? md ?? lg ?? xl ?? xxl) as T;
    case ScreenTier.sm:
      return (sm ?? xs ?? xxs ?? md ?? lg ?? xl ?? xxl) as T;
    case ScreenTier.md:
      return (md ?? sm ?? xs ?? xxs ?? lg ?? xl ?? xxl) as T;
    case ScreenTier.lg:
      return (lg ?? md ?? sm ?? xs ?? xxs ?? xl ?? xxl) as T;
    case ScreenTier.xl:
      return (xl ?? lg ?? md ?? sm ?? xs ?? xxs ?? xxl) as T;
    case ScreenTier.xxl:
      return (xxl ?? xl ?? lg ?? md ?? sm ?? xs ?? xxs) as T;
  }
}