widthFillingPlatformView method

Widget widthFillingPlatformView({
  1. required Size originalAdSize,
  2. required Size innerViewSize,
  3. required Size outerViewSize,
})

광고 플랫폼 뷰를 너비에 맞춰 표시하는 위젯을 생성합니다.

이 함수는 광고의 원본 크기와 목표 뷰 크기를 비교하여, 광고를 중앙 정렬하면서도 너비를 채우도록 조정합니다.

originalAdSize 광고의 원본 크기 innerViewSize 스크롤 뷰 내(inner)에 위치한 광고의 사이즈 outerHeight 스크롤 뷰(바깥 / outer)의 높이

Implementation

Widget widthFillingPlatformView({
  required Size originalAdSize,
  required Size innerViewSize,
  required Size outerViewSize,
}) {
  final double topPadding;

  // 목표 뷰 높이가 한계 높이보다 작은 경우:
  // - 상단 패딩을 추가하여 광고를 중앙에 배치
  if (innerViewSize.height < outerViewSize.height) {
    topPadding = (outerViewSize.height - innerViewSize.height) / 2;
  } else {
    topPadding = 0.0;
  }

  return Container(
    width: outerViewSize.width,
    height: outerViewSize.height,
    child: ScrollConfiguration(
      // 스크롤 효과는 불필요함으로, false 세팅
      behavior: const ScrollBehavior().copyWith(
        overscroll: false,
      ),
      child: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        // 사용자 스크롤을 비활성함
        physics: const NeverScrollableScrollPhysics(),
        clipBehavior: Clip.hardEdge,
        controller: scrollController,
        child: Column(
          children: [
            // 상단 패딩: 광고를 수직 중앙에 배치하기 위한 공간
            SizedBox(height: topPadding),
            Container(
              // FittedBox를 사용하여 광고 크기를 유연하게 조정
              // BoxFit.contain을 사용하여 비율을 유지하면서 컨테이너에 맞춤
              child: FittedBox(
                fit: BoxFit.contain,
                child: Container(
                  child: platformView,
                  width: originalAdSize.width,
                  height: originalAdSize.height,
                ),
              ),
              width: innerViewSize.width,
              height: innerViewSize.height,
            ),
          ],
        ),
      ),
    ),
  );
}