ForScreenSize<T> function

T ForScreenSize<T>(
  1. BuildContext context, {
  2. T? mobile,
  3. T? tablet,
  4. T? desktop,
  5. T? defaultValue,
})

Implementation

T ForScreenSize<T>(
  BuildContext context, {
  T? mobile,
  T? tablet,
  T? desktop,
  T? defaultValue,
}) {
  final layoutInfo = sunny.get<LayoutInfo>(context: context);
  switch (layoutInfo.screenType) {
    case DeviceScreenType.mobile:
      return mobile ?? defaultValue as T;
    case DeviceScreenType.tablet:
      return tablet ?? desktop ?? defaultValue as T;
    case DeviceScreenType.desktop:
      return desktop ?? defaultValue as T;
    case DeviceScreenType.watch:
      return defaultValue as T;

    default:
      return defaultValue as T;
  }
}