flutter_linear_calendar 2.0.2
flutter_linear_calendar: ^2.0.2 copied to clipboard
A reusable horizontal date selector widget for Flutter.
π LinearCalendar #
A flexible, horizontally scrollable calendar widget for Flutter, designed for simplicity, extensibility, and visual clarity.
πΈ Screenshots #
πΉ Default Usage #
LinearCalendar(
onDateChanged: (date) {
debugPrint('Selected date: $date');
},
)
πΈ Customized Style #
LinearCalendar(
initialSelectedDate: DateTime(2025, 5, 15),
selectedColor: Colors.deepPurple,
unselectedColor: Colors.grey,
foregroundColor: Colors.white,
onDateChanged: (date) {
debugPrint('Selected date: $date');
},
)
β¨ Features #
- π Horizontally scrollable calendar
- π Auto-scrolls to today or selected date
- π¨ Fully customizable colors and builders
- π Locale support and internationalization
- πΉ Long-press interaction support
- π± Haptic feedback on selection
- π― Highlights todayβs date with a dot
- π Works with
ScrollControllerand RTL layout - π§© Supports dynamic date ranges (before/after today)
- π§ Ready for state restoration logic
π Installation #
Add the package to your pubspec.yaml:
dependencies:
flutter_linear_calendar: ^2.0.0
Then run:
flutter pub get
βοΈ Parameters #
| Property | Type | Required | Description |
|---|---|---|---|
onDateChanged |
ValueChanged<DateTime> |
β | Called when a date is selected |
startDate |
DateTime? |
β | Start of the calendar range (defaults to today - daysBeforeToday) |
endDate |
DateTime? |
β | End of the calendar range (defaults to today + daysAfterToday) |
daysBeforeToday |
int |
β | Dynamic generation: number of days before today (default: 0) |
daysAfterToday |
int |
β | Dynamic generation: number of days after today (default: 30) |
initialSelectedDate |
DateTime? |
β | Initially selected date (default: today) |
selectedColor |
Color? |
β | Background color for selected date |
unselectedColor |
Color? |
β | Background color for unselected dates |
foregroundColor |
Color? |
β | Text and indicator color |
scrollController |
ScrollController? |
β | Custom scroll controller |
locale |
Locale? |
β | Use for custom month/day formatting |
onLongPress |
ValueChanged<DateTime>? |
β | Callback when a date is long-pressed |
dateBuilder |
Widget Function(...) |
β | Provide a custom widget for each date cell |
rangeSelection |
bool |
β | Placeholder for future multi-date selection support |
π§ͺ Example #
LinearCalendar(
initialSelectedDate: DateTime.now(),
daysBeforeToday: 10,
daysAfterToday: 20,
selectedColor: Colors.teal,
unselectedColor: Colors.teal.withOpacity(0.2),
foregroundColor: Colors.black,
locale: const Locale('en'),
onDateChanged: (date) => debugPrint("Selected: $date"),
onLongPress: (date) => debugPrint("Long-pressed: $date"),
dateBuilder: (context, date, isSelected) {
return Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: isSelected ? Colors.amber : Colors.transparent,
borderRadius: BorderRadius.circular(6),
),
child: Text(
DateFormat('EEE\nd', 'en').format(date),
textAlign: TextAlign.center,
style: TextStyle(
color: isSelected ? Colors.white : Colors.black87,
fontWeight: FontWeight.w500,
),
),
);
},
)
π§ Tips #
- You can dynamically control the range via
daysBeforeTodayanddaysAfterTodaywithout needing to manually passstartDate/endDate. - To highlight today, a subtle dot is shown under the day name.
- Use
ScrollControllerto programmatically scroll or attach scroll behaviors. - Use
localeto support non-English months/days (e.g., Arabic, French).
π License #
This package is distributed under the MIT license. See LICENSE for more information.
π€ Author #
Developed with β€οΈ by PearlGrell