Skip to content

Commit bf96be6

Browse files
Updated document
1 parent 5c77389 commit bf96be6

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
1-
# getting-datetime-calendar-fluter
2-
How to get datetime details while tapping header, view header and cells in Flutter event calendar?
1+
# Getting datetime details while tapping header, view header, agenda view and cells in Flutter event calendar.
2+
3+
In flutter event calendar, you can get the tapped `DateTime` details of header, view header and calendar cell using `OnTap` event of the calendar.
4+
5+
## Step 1
6+
In initState(), set the default values such as view, alert dialog texts.
7+
```xml
8+
CalendarView _calendarView;
9+
String _text, _titleText;
10+
11+
@override
12+
void initState() {
13+
_calendarView = CalendarView.week;
14+
_text='';
15+
_titleText='';
16+
super.initState();
17+
}
18+
```
19+
## Step 2
20+
Trigger `onTap` callback of flutter calendar. Please find the following code for calendar.
21+
```xml
22+
Expanded(
23+
child: SfCalendar(
24+
viewHeaderStyle:
25+
ViewHeaderStyle(backgroundColor: viewHeaderColor),
26+
backgroundColor: calendarColor,
27+
view: _calendarView,
28+
onTap: calendarTapped,
29+
),
30+
),
31+
```
32+
33+
## Step 3
34+
Using `OnTap` event get the target tapped element details such as header, view header, time slots, agenda view and get the date time values from the callback and assign it to the content of the alert dialog widget.
35+
```xml
36+
void calendarTapped(CalendarTapDetails details) {
37+
if (details.targetElement == CalendarElement.header) {
38+
_text = DateFormat('MMMM yyyy')
39+
.format(details.date)
40+
.toString();
41+
_titleText='Header';
42+
}
43+
else if (details.targetElement == CalendarElement.viewHeader) {
44+
_text = DateFormat('EEEE dd, MMMM yyyy')
45+
.format(details.date)
46+
.toString();
47+
_titleText='View Header';
48+
}
49+
else if (details.targetElement == CalendarElement.calendarCell) {
50+
_text = DateFormat('EEEE dd, MMMM yyyy')
51+
.format(details.date)
52+
.toString();
53+
_titleText='Time slots';
54+
}
55+
showDialog(
56+
context: context,
57+
builder: (BuildContext context) {
58+
return AlertDialog(
59+
title:Container(child: new Text(" $_titleText")),
60+
content:Container(child: new Text(" $_text")),
61+
actions: <Widget>[
62+
new FlatButton(onPressed: (){
63+
Navigator.of(context).pop();
64+
}, child: new Text('close'))
65+
],
66+
);
67+
});
68+
}
69+
```
70+
![header](https://github.com/SyncfusionExamples/getting-datetime-calendar-fluter/blob/master/screenshots/header.jpg)
71+
![view header](https://github.com/SyncfusionExamples/getting-datetime-calendar-fluter/blob/master/screenshots/view%20header.jpg)
72+
![cells](https://github.com/SyncfusionExamples/getting-datetime-calendar-fluter/blob/master/screenshots/cells.jpg)
73+

0 commit comments

Comments
 (0)