Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding multi date range feature #670

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@ class _StartPageState extends State<StartPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar Example'),
title: const Text('TableCalendar Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 20.0),
ElevatedButton(
child: Text('Basics'),
child: const Text('Basics'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => TableBasicsExample()),
),
),
const SizedBox(height: 12.0),
ElevatedButton(
child: Text('Range Selection'),
child: const Text('Range Selection'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => TableRangeExample()),
),
),
const SizedBox(height: 12.0),
ElevatedButton(
child: Text('Events'),
child: const Text('Events'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => TableEventsExample()),
),
),
const SizedBox(height: 12.0),
ElevatedButton(
child: Text('Multiple Selection'),
child: const Text('Multiple Selection'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => TableMultiExample()),
),
),
const SizedBox(height: 12.0),
ElevatedButton(
child: Text('Complex'),
child: const Text('Complex'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => TableComplexExample()),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/basics_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _TableBasicsExampleState extends State<TableBasicsExample> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar - Basics'),
title: const Text('TableCalendar - Basics'),
),
body: TableCalendar(
firstDay: kFirstDay,
Expand Down
23 changes: 13 additions & 10 deletions example/lib/pages/complex_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _TableComplexExampleState extends State<TableComplexExample> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar - Complex'),
title: const Text('TableCalendar - Complex'),
),
body: Column(
children: [
Expand All @@ -122,13 +122,13 @@ class _TableComplexExampleState extends State<TableComplexExample> {
},
onLeftArrowTap: () {
_pageController.previousPage(
duration: Duration(milliseconds: 300),
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
},
onRightArrowTap: () {
_pageController.nextPage(
duration: Duration(milliseconds: 300),
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
},
Expand All @@ -141,8 +141,11 @@ class _TableComplexExampleState extends State<TableComplexExample> {
focusedDay: _focusedDay.value,
headerVisible: false,
selectedDayPredicate: (day) => _selectedDays.contains(day),
rangeStartDay: _rangeStart,
rangeEndDay: _rangeEnd,
ranges: [
if (_rangeStart != null) DateRange(_rangeStart!, _rangeEnd)
],
// rangeStartDay: _rangeStart,
// rangeEndDay: _rangeEnd,
calendarFormat: _calendarFormat,
rangeSelectionMode: _rangeSelectionMode,
eventLoader: _getEventsForDay,
Expand Down Expand Up @@ -224,27 +227,27 @@ class _CalendarHeader extends StatelessWidget {
width: 120.0,
child: Text(
headerText,
style: TextStyle(fontSize: 26.0),
style: const TextStyle(fontSize: 26.0),
),
),
IconButton(
icon: Icon(Icons.calendar_today, size: 20.0),
icon: const Icon(Icons.calendar_today, size: 20.0),
visualDensity: VisualDensity.compact,
onPressed: onTodayButtonTap,
),
if (clearButtonVisible)
IconButton(
icon: Icon(Icons.clear, size: 20.0),
icon: const Icon(Icons.clear, size: 20.0),
visualDensity: VisualDensity.compact,
onPressed: onClearButtonTap,
),
const Spacer(),
IconButton(
icon: Icon(Icons.chevron_left),
icon: const Icon(Icons.chevron_left),
onPressed: onLeftArrowTap,
),
IconButton(
icon: Icon(Icons.chevron_right),
icon: const Icon(Icons.chevron_right),
onPressed: onRightArrowTap,
),
],
Expand Down
11 changes: 7 additions & 4 deletions example/lib/pages/events_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _TableEventsExampleState extends State<TableEventsExample> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar - Events'),
title: const Text('TableCalendar - Events'),
),
body: Column(
children: [
Expand All @@ -95,13 +95,16 @@ class _TableEventsExampleState extends State<TableEventsExample> {
lastDay: kLastDay,
focusedDay: _focusedDay,
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
rangeStartDay: _rangeStart,
rangeEndDay: _rangeEnd,
ranges: [
if (_rangeStart != null) DateRange(_rangeStart!, _rangeEnd)
],
// rangeStartDay: _rangeStart,
// rangeEndDay: _rangeEnd,
calendarFormat: _calendarFormat,
rangeSelectionMode: _rangeSelectionMode,
eventLoader: _getEventsForDay,
startingDayOfWeek: StartingDayOfWeek.monday,
calendarStyle: CalendarStyle(
calendarStyle: const CalendarStyle(
// Use `CalendarStyle` to customize the UI
outsideDaysVisible: false,
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/multi_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _TableMultiExampleState extends State<TableMultiExample> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar - Multi'),
title: const Text('TableCalendar - Multi'),
),
body: Column(
children: [
Expand Down Expand Up @@ -90,7 +90,7 @@ class _TableMultiExampleState extends State<TableMultiExample> {
},
),
ElevatedButton(
child: Text('Clear selection'),
child: const Text('Clear selection'),
onPressed: () {
setState(() {
_selectedDays.clear();
Expand Down
7 changes: 4 additions & 3 deletions example/lib/pages/range_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ class _TableRangeExampleState extends State<TableRangeExample> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TableCalendar - Range'),
title: const Text('TableCalendar - Range'),
),
body: TableCalendar(
firstDay: kFirstDay,
lastDay: kLastDay,
focusedDay: _focusedDay,
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
rangeStartDay: _rangeStart,
rangeEndDay: _rangeEnd,
ranges: [if (_rangeStart != null) DateRange(_rangeStart!, _rangeEnd)],
// rangeStartDay: _rangeStart,
// rangeEndDay: _rangeEnd,
calendarFormat: _calendarFormat,
rangeSelectionMode: _rangeSelectionMode,
onDaySelected: (selectedDay, focusedDay) {
Expand Down
10 changes: 4 additions & 6 deletions example/lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ final kEvents = LinkedHashMap<DateTime, List<Event>>(
hashCode: getHashCode,
)..addAll(_kEventSource);

final _kEventSource = Map.fromIterable(List.generate(50, (index) => index),
key: (item) => DateTime.utc(kFirstDay.year, kFirstDay.month, item * 5),
value: (item) => List.generate(
item % 4 + 1, (index) => Event('Event $item | ${index + 1}')))
final _kEventSource = { for (var item in List.generate(50, (index) => index)) DateTime.utc(kFirstDay.year, kFirstDay.month, item * 5) : List.generate(
item % 4 + 1, (index) => Event('Event $item | ${index + 1}'),) }
..addAll({
kToday: [
Event('Today\'s Event 1'),
Event('Today\'s Event 2'),
const Event('Today\'s Event 1'),
const Event('Today\'s Event 2'),
],
});

Expand Down
23 changes: 8 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -101,7 +101,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
simple_gesture_detector:
dependency: transitive
description:
Expand All @@ -120,7 +120,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -162,21 +162,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.17.0"
6 changes: 3 additions & 3 deletions lib/src/customization/calendar_builders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import '../shared/utils.dart' show DayBuilder, FocusedDayBuilder;
/// Signature for a function that creates a single event marker for a given `day`.
/// Contains a single `event` associated with that `day`.
typedef SingleMarkerBuilder<T> = Widget? Function(
BuildContext context, DateTime day, T event);
BuildContext context, DateTime day, T event,);

/// Signature for a function that creates an event marker for a given `day`.
/// Contains a list of `events` associated with that `day`.
typedef MarkerBuilder<T> = Widget? Function(
BuildContext context, DateTime day, List<T> events);
BuildContext context, DateTime day, List<T> events,);

/// Signature for a function that creates a background highlight for a given `day`.
///
/// Used for highlighting current range selection.
/// Contains a value determining if the given `day` falls within the selected range.
typedef HighlightBuilder = Widget? Function(
BuildContext context, DateTime day, bool isWithinRange);
BuildContext context, DateTime day, bool isWithinRange,);

/// Class containing all custom builders for `TableCalendar`.
class CalendarBuilders<T> {
Expand Down
30 changes: 15 additions & 15 deletions lib/src/customization/calendar_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,55 +164,55 @@ class CalendarStyle {
this.markersOffset = const PositionedOffset(),
this.rangeHighlightColor = const Color(0xFFBBDDFF),
this.markerDecoration = const BoxDecoration(
color: const Color(0xFF263238),
color: Color(0xFF263238),
shape: BoxShape.circle,
),
this.todayTextStyle = const TextStyle(
color: const Color(0xFFFAFAFA),
color: Color(0xFFFAFAFA),
fontSize: 16.0,
), //
this.todayDecoration = const BoxDecoration(
color: const Color(0xFF9FA8DA),
color: Color(0xFF9FA8DA),
shape: BoxShape.circle,
),
this.selectedTextStyle = const TextStyle(
color: const Color(0xFFFAFAFA),
color: Color(0xFFFAFAFA),
fontSize: 16.0,
),
this.selectedDecoration = const BoxDecoration(
color: const Color(0xFF5C6BC0),
color: Color(0xFF5C6BC0),
shape: BoxShape.circle,
),
this.rangeStartTextStyle = const TextStyle(
color: const Color(0xFFFAFAFA),
color: Color(0xFFFAFAFA),
fontSize: 16.0,
),
this.rangeStartDecoration = const BoxDecoration(
color: const Color(0xFF6699FF),
color: Color(0xFF6699FF),
shape: BoxShape.circle,
),
this.rangeEndTextStyle = const TextStyle(
color: const Color(0xFFFAFAFA),
color: Color(0xFFFAFAFA),
fontSize: 16.0,
),
this.rangeEndDecoration = const BoxDecoration(
color: const Color(0xFF6699FF),
color: Color(0xFF6699FF),
shape: BoxShape.circle,
),
this.withinRangeTextStyle = const TextStyle(),
this.withinRangeDecoration = const BoxDecoration(shape: BoxShape.circle),
this.outsideTextStyle = const TextStyle(color: const Color(0xFFAEAEAE)),
this.outsideTextStyle = const TextStyle(color: Color(0xFFAEAEAE)),
this.outsideDecoration = const BoxDecoration(shape: BoxShape.circle),
this.disabledTextStyle = const TextStyle(color: const Color(0xFFBFBFBF)),
this.disabledTextStyle = const TextStyle(color: Color(0xFFBFBFBF)),
this.disabledDecoration = const BoxDecoration(shape: BoxShape.circle),
this.holidayTextStyle = const TextStyle(color: const Color(0xFF5C6BC0)),
this.holidayTextStyle = const TextStyle(color: Color(0xFF5C6BC0)),
this.holidayDecoration = const BoxDecoration(
border: const Border.fromBorderSide(
const BorderSide(color: const Color(0xFF9FA8DA), width: 1.4),
border: Border.fromBorderSide(
BorderSide(color: Color(0xFF9FA8DA), width: 1.4),
),
shape: BoxShape.circle,
),
this.weekendTextStyle = const TextStyle(color: const Color(0xFF5A5A5A)),
this.weekendTextStyle = const TextStyle(color: Color(0xFF5A5A5A)),
this.weekendDecoration = const BoxDecoration(shape: BoxShape.circle),
this.defaultTextStyle = const TextStyle(),
this.defaultDecoration = const BoxDecoration(shape: BoxShape.circle),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/customization/days_of_week_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DaysOfWeekStyle {
const DaysOfWeekStyle({
this.dowTextFormatter,
this.decoration = const BoxDecoration(),
this.weekdayStyle = const TextStyle(color: const Color(0xFF4F4F4F)),
this.weekendStyle = const TextStyle(color: const Color(0xFF6A6A6A)),
this.weekdayStyle = const TextStyle(color: Color(0xFF4F4F4F)),
this.weekendStyle = const TextStyle(color: Color(0xFF6A6A6A)),
});
}
Loading