adaptiveOrientation<T> method

T adaptiveOrientation<T>({
  1. required T phonePortrait,
  2. T? phoneLandscape,
  3. T? tabletPortrait,
  4. T? tabletLandscape,
  5. T? desktopPortrait,
  6. T? desktopLandscape,
})

Gets a value based on device type AND orientation.

final padding = context.adaptiveOrientation<double>(
  phonePortrait: 16,
  phoneLandscape: 8,
  tabletPortrait: 24,
  tabletLandscape: 16,
);

Implementation

T adaptiveOrientation<T>({
  required T phonePortrait,
  T? phoneLandscape,
  T? tabletPortrait,
  T? tabletLandscape,
  T? desktopPortrait,
  T? desktopLandscape,
}) {
  final landscape = isLandscape;

  switch (deviceType) {
    case DeviceType.phone:
      return landscape ? (phoneLandscape ?? phonePortrait) : phonePortrait;
    case DeviceType.tablet:
      final portrait = tabletPortrait ?? phonePortrait;
      return landscape ? (tabletLandscape ?? portrait) : portrait;
    case DeviceType.desktop:
      final portrait = desktopPortrait ?? tabletPortrait ?? phonePortrait;
      return landscape ? (desktopLandscape ?? portrait) : portrait;
    case DeviceType.foldable:
      return landscape ? (phoneLandscape ?? phonePortrait) : phonePortrait;
  }
}