when<T> method

T when<T>(
  1. T? phone,
  2. T? tablet,
  3. T? computer
)

Returns a value based on the current device type.

  • phone: Value to return if the device is a phone.
  • tablet: Value to return if the device is a tablet.
  • computer: Value to return if the device is a computer.

Example usage:

final rp = Provider.of<ResponsiveProvider>(context);
final flexWidth = rp.when(
  1.0, // for Phone
  1/2, // for Tablet
  1/4, // for Computer
);

Implementation

T when<T>(T? phone, T? tablet, T? computer) {
  if (breakpoint.isPhone() && phone != null) {
    return phone;
  } else if (breakpoint.isTablet() && tablet != null) {
    return tablet;
  }
  return computer ?? tablet ?? phone ?? (throw Exception('You must specified at least one value'));
}