ResponsiveItem<R> function
R
ResponsiveItem<R>(
- BuildContext context, {
- ResponsiveExpression<
R> ? mobile, - ResponsiveExpression<
R> ? tablet, - ResponsiveExpression<
R> ? desktop, - R? defaultValue,
Implementation
R ResponsiveItem<R>(
BuildContext context, {
ResponsiveExpression<R>? mobile,
ResponsiveExpression<R>? tablet,
ResponsiveExpression<R>? desktop,
R? defaultValue,
}) {
if (mobile == null && desktop == null && tablet == null) {
return defaultValue as R;
}
final layoutInfo = sunny.get<LayoutInfo>(context: context);
switch (layoutInfo.screenType) {
case DeviceScreenType.mobile:
return mobile != null ? mobile(context) : defaultValue as R;
case DeviceScreenType.tablet:
final fn = tablet ?? desktop;
return fn != null ? fn(context) : defaultValue as R;
case DeviceScreenType.desktop:
return desktop != null ? desktop(context) : defaultValue as R;
case DeviceScreenType.watch:
return defaultValue as R;
default:
return throw "Invalid type: ${layoutInfo.screenType}";
}
}