Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Flutter Table Calendar – Highly customizable, feature-packed

Table Calendar

Highly customizable, feature-packed Flutter Calendar with gestures, animations, and multiple formats.

Table Calendar with custom stylesTable Calendar with Builders

Features

Usage

Make sure to check out example project. For additional info please refer to API docs.

Installation

Add to pubspec.yaml:

dependencies:
  table_calendar: ^2.2.2

Then import it to your project:

import 'package:table_calendar/table_calendar.dart';

And finally create the TableCalendar with a CalendarController:

@override
void initState() {
  super.initState();
  _calendarController = CalendarController();
}

@override
void dispose() {
  _calendarController.dispose();
  super.dispose();
}

@override
Widget build(BuildContext context) {
  return TableCalendar(
    calendarController: _calendarController,
  );
}

Locale

Table Calendar supports locales. 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 need to initialize the i18n formatting.

This is independent of Table Calendar package, so I encourage you to do your own research.

A simple way of doing it is as follows:

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 Table Calendar 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 Table Calendar use Polish language:

TableCalendar(
  locale: 'pl_PL',
),
'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.

Holidays

Table Calendar provides a simple interface for displaying holidays. Here are a few steps to follow:

{
  `DateTime A`: [`Holiday A1`, `Holiday A2`, ...],
  `DateTime B`: [`Holiday B1`, `Holiday B2`, ...],
  ...
}

And that’s your basic setup! Now you can add some styling:

You can also add custom holiday markers thanks to improved marker API. Check out example project for more details.

markersBuilder: (context, date, events, holidays) {
  final children = <Widget>[];

  if (events.isNotEmpty) {
    children.add(
      Positioned(
        right: 1,
        bottom: 1,
        child: _buildEventsMarker(date, events),
      ),
    );
  }

  if (holidays.isNotEmpty) {
    children.add(
      Positioned(
        right: -2,
        top: -2,
        child: _buildHolidaysMarker(),
      ),
    );
  }

  return children;
},

Download Flutter Table Calendar Source Code on GitHub

Exit mobile version