분류, 패키지 및 저장소 검색

table_calendar 표지
패키지 상세v3.3.0

table_calendar

Flutter용으로 매우 사용자 정의가 가능하고 기능이 풍부한 캘린더 위젯입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
74.3만
좋아요
3.3천
Pub 점수
160

패키지 설치

flutter pub add table_calendar

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

TableCalendar는 Flutter용으로 설계된 매우 사용자 정의가 가능하고 기능이 풍부한 캘린더 위젯으로, 다양한 사용 사례를 지원하기 위해 광범위한 구성 옵션을 제공합니다. Android, iOS, Web, macOS, Windows, Linux 등의 주요 플랫폼에서 깔끔하고 반응형인 테이블 기반 레이아웃을 제공합니다. 이 패키지는 이벤트 마킹, 날짜 선택, 탐색 컨트롤 및 동적 스타일링을 지원하여 상호작용 가능한 캘린더 기능이 필요한 앱에 적합합니다. 모듈식 설계로 개발자는 앱의 특정 요구사항에 맞게 외관과 동작을 조정할 수 있습니다.

사용 사례

  • 이벤트 스케줄링 앱
  • 작업 관리 도구
  • 예약 및 예약 시스템
  • 일일 계획 앱
  • 날짜 선택기 통합
  • 사용자 정의 캘린더 뷰

주요 기능

  • 완전히 사용자 정의 가능한 UI
  • 다중 날짜 선택 모드
  • 이벤트 강조
  • 내장된 탐색 컨트롤
  • 다중 플랫폼에 걸친 반응형 디자인
  • 확장 가능한 이벤트 및 날짜 처리

적합한 대상

  • 캘린더 중심 앱을 개발하는 개발자
  • 다중 플랫폼 간 캘린더 일관성을 필요로 하는 팀
  • 고급 날짜 상호작용이 필요한 앱
  • 유연한 시각적 사용자 정의를 원하는 디자이너

고려 사항

  • 복잡한 레이아웃을 위해 추가 스타일링이 필요할 수 있습니다
  • 대규모 데이터 세트의 성능 영향
  • 고급 기능 학습 곡선
  • 제한된 내장 지역화 지원
  • 이벤트를 처리하기 위해 외부 상태 관리에 의존

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

TableCalendar

Pub Package Awesome Flutter

Highly customizable, feature-packed calendar widget for Flutter.

Image Image
TableCalendar with custom styles TableCalendar with custom builders

Features

  • Extensive, yet easy to use API
  • Preconfigured UI with customizable styling
  • Custom selective builders for unlimited UI design
  • Locale support
  • Range selection support
  • Multiple selection support
  • Dynamic events and holidays
  • Vertical autosizing - fit the content, or fill the viewport
  • Multiple calendar formats (month, two weeks, week)
  • Horizontal swipe boundaries (first day, last day)

Usage

Make sure to check out examples and API docs for more details.

Installation

Add the following line to pubspec.yaml:

dependencies:
  table_calendar: ^3.2.1
Basic setup

The complete example is available here.

TableCalendar requires you to provide firstDay, lastDay and focusedDay:

  • firstDay is the first available day for the calendar. Users will not be able to access days before it.
  • lastDay is the last available day for the calendar. Users will not be able to access days after it.
  • focusedDay is the currently targeted day. Use this property to determine which month should be currently visible.
TableCalendar(
  firstDay: DateTime.utc(2010, 10, 16),
  lastDay: DateTime.utc(2030, 3, 14),
  focusedDay: DateTime.now(),
);
Adding interactivity

You will surely notice that previously set up calendar widget isn't quite interactive - you can only swipe it horizontally, to change the currently visible month. While it may be sufficient in certain situations, you can easily bring it to life by specifying a couple of callbacks.

Adding the following code to the calendar widget will allow it to respond to user's taps, marking the tapped day as selected:

selectedDayPredicate: (day) {
  return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
  setState(() {
    _selectedDay = selectedDay;
    _focusedDay = focusedDay; // update `_focusedDay` here as well
  });
},

In order to dynamically update visible calendar format, add those lines to the widget:

calendarFormat: _calendarFormat,
onFormatChanged: (format) {
  setState(() {
    _calendarFormat = format;
  });
},

Those two changes will make the calendar interactive and responsive to user's input.

Updating focusedDay

Setting focusedDay to a static value means that whenever TableCalendar widget rebuilds, it will use that specific focusedDay. You can quickly test it by using hot reload: set focusedDay to DateTime.now(), swipe to next month and trigger a hot reload - the calendar will "reset" to its initial state. To prevent this from happening, you should store and update focusedDay whenever any callback exposes it.

Add this one callback to complete the basic setup:

onPageChanged: (focusedDay) {
  _focusedDay = focusedDay;
},

It is worth noting that you don't need to call setState() inside onPageChanged() callback. You should just update the stored value, so that if the widget gets rebuilt later on, it will use the proper focusedDay.

The complete example is available here. You can find other examples here.

Events

The complete example is available here.

You can supply custom events to TableCalendar widget. To do so, use eventLoader property - you will be given a DateTime object, to which you need to assign a list of events.

eventLoader: (day) {
  return _getEventsForDay(day);
},

_getEventsForDay() can be of any implementation. For example, a Map<DateTime, List<T>> can be used:

List<Event> _getEventsForDay(DateTime day) {
  return events[day] ?? [];
}

One thing worth remembering is that DateTime objects consist of both date and time parts. In many cases this time part is redundant for calendar related aspects.

If you decide to use a Map, I suggest making it a LinkedHashMap - this will allow you to override equality comparison for two DateTime objects, comparing them just by their date parts:

final events = LinkedHashMap(
  equals: isSameDay,
  hashCode: getHashCode,
)..addAll(eventSource);
Cyclic events

eventLoader allows you to easily add events that repeat in a pattern. For example, this will add an event to every Monday:

eventLoader: (day) {
  if (day.weekday == DateTime.monday) {
    return [Event('Cyclic event')];
  }

  return [];
},
Events selected on tap

Often times having a sublist of events that are selected by tapping on a day is desired. You can achieve that by using the same method you provided to eventLoader inside of onDaySelected callback:

void _onDaySelected(DateTime selectedDay, DateTime focusedDay) {
  if (!isSameDay(_selectedDay, selectedDay)) {
    setState(() {
      _focusedDay = focusedDay;
      _selectedDay = selectedDay;
      _selectedEvents = _getEventsForDay(selectedDay);
    });
  }
}

The complete example is available here.

Custom UI with CalendarBuilders

To customize the UI with your own widgets, use CalendarBuilders. Each builder can be used to selectively override the UI, allowing you to implement highly specific designs with minimal hassle.

You can return null from any builder to use the default style. For example, the following snippet will override only the Sunday's day of the week label (Sun), leaving other dow labels unchanged:

calendarBuilders: CalendarBuilders(
  dowBuilder: (context, day) {
    if (day.weekday == DateTime.sunday) {
      final text = DateFormat.E().format(day);

      return Center(
        child: Text(
          text,
          style: TextStyle(color: Colors.red),
        ),
      );
    }
  },
),
Locale

To display the calendar in desired language, use locale property. If you don't specify it, a default locale will be used.

Initialization

Before you can use a locale, you might need to initialize date formatting.

A simple way of doing it is as follows:

  • First of all, add intl package to your pubspec.yaml file
  • Then make modifications to your main():
import 'package:intl/date_symbol_data_local.dart';

void main() {
  initializeDateFormatting().then((_) => runApp(MyApp()));
}

After those two steps your app should be ready to use TableCalendar with different languages.

Specifying a language

To specify a language, simply pass it as a String code to locale property.

For example, this will make TableCalendar use Polish language:

TableCalendar(
  locale: 'pl_PL',
),
Image Image Image Image
'en_US' 'pl_PL' 'fr_FR' 'zh_CN'

Note, that if you want to change the language of FormatButton's text, you have to do this yourself. Use availableCalendarFormats property and pass the translated Strings there. Use i18n method of your choice.

You can also hide the button altogether by setting formatButtonVisible to false.

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

순위