[flutter] 스크롤바를 사용하여 캘린더 구현하기

이번에는 Flutter에서 스크롤바를 사용하여 캘린더를 구현하는 방법에 대해 알아보겠습니다.

1. 기본 캘린더 위젯 추가하기

먼저, 기본적인 캘린더 위젯을 추가해야 합니다. flutter_calendar_carousel 패키지를 사용하여 캘린더를 쉽게 추가할 수 있습니다.

dependencies:
  flutter_calendar_carousel: ^1.5.3

위와 같이 패키지를 추가하고, 다음과 같이 캘린더 위젯을 구현합니다.

import 'package:flutter/material.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart' show CalendarCarousel;

class CalendarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('캘린더'),
      ),
      body: CalendarCarousel(
        thisMonthDayBorderColor: Colors.grey,
        height: 420.0,
        daysHaveCircularBorder: null,
      )
    );
  }
}

2. 스크롤바 추가하기

이제 스크롤바를 추가하는 방법에 대해 알아봅시다. SingleChildScrollView 위젯을 사용하여 스크롤바를 구현할 수 있습니다.

import 'package:flutter/material.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart' show CalendarCarousel;

class ScrollableCalendarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('스크롤 가능한 캘린더'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            SizedBox(
              height: 20,
            ),
            CalendarCarousel(
              thisMonthDayBorderColor: Colors.grey,
              height: 420.0,
              daysHaveCircularBorder: null,
            ),
            SizedBox(
              height: 500, // scrollbar height
            ),
          ],
        ),
      ),
    );
  }
}

마치며

이제 Flutter에서 스크롤바를 사용하여 캘린더를 구현하는 방법을 알아보았습니다. 위의 코드를 참고하여 쉽게 캘린더와 스크롤바를 함께 사용할 수 있을 것입니다.