help<T> method

T help<T>({
  1. T? mobileSmall,
  2. T? mobileSmallLandscape,
  3. T? mobileNormal,
  4. T? mobileNormalLandscape,
  5. T? mobileLarge,
  6. T? mobileLargeLandscape,
  7. T? mobileExtraLarge,
  8. T? mobileExtraLargeLandscape,
  9. T? tabletSmall,
  10. T? tabletSmallLandscape,
  11. T? tabletNormal,
  12. T? tabletNormalLandscape,
  13. T? tabletLarge,
  14. T? tabletLargeLandscape,
  15. T? tabletExtraLarge,
  16. T? tabletExtraLargeLandscape,
  17. T? desktopSmall,
  18. T? desktopSmallLandscape,
  19. T? desktopNormal,
  20. T? desktopNormalLandscape,
  21. T? desktopLarge,
  22. T? desktopLargeLandscape,
  23. T? desktopExtraLarge,
  24. T? desktopExtraLargeLandscape,
})

Implementation

T help<T>({
  T? mobileSmall,
  T? mobileSmallLandscape,
  T? mobileNormal,
  T? mobileNormalLandscape,
  T? mobileLarge,
  T? mobileLargeLandscape,
  T? mobileExtraLarge,
  T? mobileExtraLargeLandscape,
  T? tabletSmall,
  T? tabletSmallLandscape,
  T? tabletNormal,
  T? tabletNormalLandscape,
  T? tabletLarge,
  T? tabletLargeLandscape,
  T? tabletExtraLarge,
  T? tabletExtraLargeLandscape,
  T? desktopSmall,
  T? desktopSmallLandscape,
  T? desktopNormal,
  T? desktopNormalLandscape,
  T? desktopLarge,
  T? desktopLargeLandscape,
  T? desktopExtraLarge,
  T? desktopExtraLargeLandscape,
}) {
  final isPortrait = _currentOrientation == Orientation.portrait;
  final closestBreakPoints =
      _oldLength == _currentLength && _oldOrientation == _currentOrientation
          ? _cachedBreakPointsList!
          : _getSortedBreakPointsByClosestTo(_currentLength);

  _oldLength = _currentLength;
  _oldOrientation = _currentOrientation;
  _cachedBreakPointsList = closestBreakPoints;

  if (_printScreenInfo)
    _printCurrentScreenInfo(
      currentLength: _currentLength,
      closestBreakPoint: closestBreakPoints.first,
      size: _size,
      isPortrait: isPortrait,
    );

  final portraitMap = {
    if (mobileSmall != null) BreakPoint.mobileSmall: mobileSmall,
    if (mobileNormal != null) BreakPoint.mobileNormal: mobileNormal,
    if (mobileLarge != null) BreakPoint.mobileLarge: mobileLarge,
    if (mobileExtraLarge != null)
      BreakPoint.mobileExtraLarge: mobileExtraLarge,
    if (tabletSmall != null) BreakPoint.tabletSmall: tabletSmall,
    if (tabletNormal != null) BreakPoint.tabletNormal: tabletNormal,
    if (tabletLarge != null) BreakPoint.tabletLarge: tabletLarge,
    if (tabletExtraLarge != null)
      BreakPoint.tabletExtraLarge: tabletExtraLarge,
    if (desktopSmall != null) BreakPoint.desktopSmall: desktopSmall,
    if (desktopNormal != null) BreakPoint.desktopNormal: desktopNormal,
    if (desktopLarge != null) BreakPoint.desktopLarge: desktopLarge,
    if (desktopExtraLarge != null)
      BreakPoint.desktopExtraLarge: desktopExtraLarge,
  };

  final landscapeMap = {
    if (mobileSmallLandscape != null)
      BreakPoint.mobileSmall: mobileSmallLandscape,
    if (mobileNormalLandscape != null)
      BreakPoint.mobileNormal: mobileNormalLandscape,
    if (mobileLargeLandscape != null)
      BreakPoint.mobileLarge: mobileLargeLandscape,
    if (mobileExtraLargeLandscape != null)
      BreakPoint.mobileExtraLarge: mobileExtraLargeLandscape,
    if (tabletSmallLandscape != null)
      BreakPoint.tabletSmall: tabletSmallLandscape,
    if (tabletNormalLandscape != null)
      BreakPoint.tabletNormal: tabletNormalLandscape,
    if (tabletLargeLandscape != null)
      BreakPoint.tabletLarge: tabletLargeLandscape,
    if (tabletExtraLargeLandscape != null)
      BreakPoint.tabletExtraLarge: tabletExtraLargeLandscape,
    if (desktopSmallLandscape != null)
      BreakPoint.desktopSmall: desktopSmallLandscape,
    if (desktopNormalLandscape != null)
      BreakPoint.desktopNormal: desktopNormalLandscape,
    if (desktopLargeLandscape != null)
      BreakPoint.desktopLarge: desktopLargeLandscape,
    if (desktopExtraLargeLandscape != null)
      BreakPoint.desktopExtraLarge: desktopExtraLargeLandscape,
  };

  final closestItem = _findClosest(
    closestBreakPoints,
    isPortrait,
    portraitMap,
    landscapeMap,
  );

  if (closestItem != null)
    return closestItem;
  else
    throw Exception(
        'Screen size not specified or there is no options passed from the parameters [currentLength: `$_currentLength`, orientation: `$_currentOrientation`]');
}