init static method

void init({
  1. required BuildContext context,
  2. required Orientation orientation,
  3. double designMinWidth = 360,
  4. double designMaxWidth = 1440,
  5. double designMinHeight = 480,
  6. double designMaxHeight = 1024,
  7. double mobilePortraitBreakpoint = 480,
  8. double mobileLandscapeBreakpoint = 768,
  9. double tabletLandscapeBreakpoint = 1024,
  10. TargetDeviceType targetDevice = TargetDeviceType.phonePortrait,
})

Initializes the ScreenAdaptiveConfig with the given context and orientation.

This method sets up the configuration for screen adaptation, including design dimensions and the target device type.

context provides the build context for media query data. orientation provides the current device orientation. designMinWidth and designMaxWidth define the minimum and maximum design widths. designMinHeight and designMaxHeight define the minimum and maximum design heights. targetDevice specifies the target device type for adaptation. mobilePortraitBreakpoint defines the small screen or mobile breakpoint. mobileLandscapeBreakpoint defines the tablet screen or mobile landscape breakpoint. tabletLandscapeBreakpoint defines the large screen or tablet landscape breakpoint.

Implementation

static void init({
  required BuildContext context,
  required Orientation orientation,
  double designMinWidth = 360,
  double designMaxWidth = 1440,
  double designMinHeight = 480,
  double designMaxHeight = 1024,
  double mobilePortraitBreakpoint = 480,
  double mobileLandscapeBreakpoint = 768,
  double tabletLandscapeBreakpoint = 1024,
  TargetDeviceType targetDevice = TargetDeviceType.phonePortrait,
}) {
  MediaQueryData mediaQueryData = MediaQuery.of(context);
  _screenWidth = mediaQueryData.size.width;
  _screenHeight = mediaQueryData.size.height;

  final screenInfo = ScreenInfo(
    width: mediaQueryData.size.width,
    height: mediaQueryData.size.height,
    mobilePortraitBreakpoint: mobilePortraitBreakpoint,
    mobileLandscapeBreakpoint: mobileLandscapeBreakpoint,
    tabletLandscapeBreakpoint: tabletLandscapeBreakpoint,
    orientation: orientation,
  );

  if (_instance == null || _instance!._hasScreenInfoChanged(screenInfo)) {
    _instance = ScreenAdaptiveConfig(
      mediaQueryData: mediaQueryData,
      screenInfo: screenInfo,
      deviceTypeConfig: DeviceTypeConfig(
        screenInfo: screenInfo,
        designMinWidth: designMinWidth,
        designMaxWidth: designMaxWidth,
        designMinHeight: designMinHeight,
        designMaxHeight: designMaxHeight,
        targetDeviceType: targetDevice,
      ),
    );
  }

  blockSizeHorizontal = _screenWidth / 100;
  blockSizeVertical = _screenHeight / 100;

  _safeAreaHorizontal =
      mediaQueryData.padding.left + mediaQueryData.padding.right;
  _safeAreaVertical =
      mediaQueryData.padding.top + mediaQueryData.padding.bottom;
  safeBlockHorizontal = (_screenWidth - _safeAreaHorizontal) / 100;
  safeBlockVertical = (_screenHeight - _safeAreaVertical) / 100;
}