getValueForRefinedSize<T> function Null safety

T getValueForRefinedSize<T>(
  1. {required BuildContext context,
  2. required T normal,
  3. T? large,
  4. T? extraLarge}
)

Will return one of the values passed in for the refined size

Implementation

T getValueForRefinedSize<T>({
  required BuildContext context,
  required T normal,
  T? large,
  T? extraLarge,
}) {
  var refinedSize = getRefinedSize(MediaQuery.of(context).size);
  // If we're at extra large size
  if (refinedSize == RefinedSize.extraLarge) {
    // If we have supplied the extra large layout then display that
    if (extraLarge != null) return extraLarge;
    // If no extra large layout is supplied we want to check if we have the size below it and display that
    if (large != null) return large;
  }

  if (refinedSize == RefinedSize.large) {
    // If we have supplied the large layout then display that
    if (large != null) return large;
    // If no large layout is supplied we want to check if we have the size below it and display that
    if (normal != null) return normal;
  }

  if (refinedSize == RefinedSize.normal) {
    // If we have supplied the normal layout then display that
    if (normal != null) return normal;
  }

  // If none of the layouts above are supplied or we're on the normal size layout then we show the normal layout
  return normal;
}