calendar_header.dart
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2019 Aleksander Woźniak
// SPDX-License-Identifier: Apache-2.0
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';
import 'package:table_calendar/src/customization/header_style.dart';
import 'package:table_calendar/src/shared/utils.dart'
show CalendarFormat, DayBuilder;
import 'package:table_calendar/src/widgets/custom_icon_button.dart';
import 'package:table_calendar/src/widgets/format_button.dart';
class CalendarHeader extends StatelessWidget {
final dynamic locale;
final DateTime focusedMonth;
final CalendarFormat calendarFormat;
final HeaderStyle headerStyle;
final VoidCallback onLeftChevronTap;
final VoidCallback onRightChevronTap;
final VoidCallback onHeaderTap;
final VoidCallback onHeaderLongPress;
final ValueChanged<CalendarFormat> onFormatButtonTap;
final Map<CalendarFormat, String> availableCalendarFormats;
final DayBuilder? headerTitleBuilder;
final VoidCallback selectPreviousYear;
final VoidCallback selectNextYear;
const CalendarHeader({
super.key,
this.locale,
required this.focusedMonth,
required this.calendarFormat,
required this.headerStyle,
required this.onLeftChevronTap,
required this.onRightChevronTap,
required this.onHeaderTap,
required this.onHeaderLongPress,
required this.onFormatButtonTap,
required this.availableCalendarFormats,
this.headerTitleBuilder,
required this.selectPreviousYear,
required this.selectNextYear,
});
// void _selectPreviousYear() {
// setState(() {
// widget.calendarController.previousPageYear();
// });
// }
// void _selectNextYear() {
// setState(() {
// widget.calendarController.nextPageYear();
// });
// }
@override
Widget build(BuildContext context) {
final text = headerStyle.titleTextFormatter?.call(focusedMonth, locale) ??
DateFormat.yMMMM(locale).format(focusedMonth);
return Container(
decoration: headerStyle.decoration,
margin: headerStyle.headerMargin,
padding: headerStyle.headerPadding,
child: Row(
children: [
InkWell(
onTap: selectPreviousYear,
child: Container(
padding: const EdgeInsets.only(left: 20),
// color: Colors.red,
child: Image.asset(
'assets/date_y_l.png',
width: 16,
height: 45,
),),),
if (headerStyle.leftChevronVisible)
CustomIconButton(
icon: headerStyle.leftChevronIcon,
onTap: onLeftChevronTap,
margin: headerStyle.leftChevronMargin,
padding: headerStyle.leftChevronPadding,
),
Expanded(
child: headerTitleBuilder?.call(context, focusedMonth) ??
GestureDetector(
onTap: onHeaderTap,
onLongPress: onHeaderLongPress,
child: Text(
text,
style: headerStyle.titleTextStyle,
textAlign: headerStyle.titleCentered
? TextAlign.center
: TextAlign.start,
),
),
),
if (headerStyle.formatButtonVisible &&
availableCalendarFormats.length > 1)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: FormatButton(
onTap: onFormatButtonTap,
availableCalendarFormats: availableCalendarFormats,
calendarFormat: calendarFormat,
decoration: headerStyle.formatButtonDecoration,
padding: headerStyle.formatButtonPadding,
textStyle: headerStyle.formatButtonTextStyle,
showsNextFormat: headerStyle.formatButtonShowsNext,
),
),
if (headerStyle.rightChevronVisible)
CustomIconButton(
icon: headerStyle.rightChevronIcon,
onTap: onRightChevronTap,
margin: headerStyle.rightChevronMargin,
padding: headerStyle.rightChevronPadding,
),
InkWell(
onTap: selectNextYear,
child: Container(
padding: const EdgeInsets.only(right: 20),
// color: Colors.red,
child: Image.asset(
'assets/date_y_r.png',
width: 12,
height: 45,
),),),
],
),
);
}
}