Skip to content

Commit 3f00594

Browse files
authored
Merge pull request #3 from Indumathi1195R/pickercalendar
Sample and Pubspec updated.
2 parents be17c22 + 9561e61 commit 3f00594

File tree

2 files changed

+51
-91
lines changed

2 files changed

+51
-91
lines changed

lib/main.dart

Lines changed: 48 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:syncfusion_flutter_calendar/calendar.dart';
44

55
void main() => runApp(InitialDisplayDate());
66

7+
78
class InitialDisplayDate extends StatelessWidget {
89
@override
910
Widget build(BuildContext context) {
@@ -13,108 +14,67 @@ class InitialDisplayDate extends StatelessWidget {
1314
);
1415
}
1516
}
16-
1717
class DisplayDate extends StatefulWidget {
1818
@override
1919
State<StatefulWidget> createState() => CalendarDisplayDate();
2020
}
21-
22-
List<String> views = <String>[
23-
'Day',
24-
'Week',
25-
'WorkWeek',
26-
'Month',
27-
'Timeline Day',
28-
'Timeline Week',
29-
'Timeline WorkWeek'
30-
];
31-
3221
class CalendarDisplayDate extends State<DisplayDate> {
33-
CalendarView _calendarView;
34-
DateTime _datePicked;
35-
DateTime _calendarDate;
36-
37-
@override
38-
void initState() {
39-
// TODO: implement initState
40-
_calendarView = CalendarView.week;
41-
_datePicked = DateTime.now();
42-
_calendarDate = DateTime.now();
43-
super.initState();
44-
}
22+
final CalendarController _controller = CalendarController();
23+
DateTime? _datePicked = DateTime.now();
4524

4625
@override
4726
Widget build(BuildContext context) {
48-
return Scaffold(
49-
appBar: AppBar(
50-
actions: <Widget>[
51-
FlatButton(
52-
onPressed: () {
53-
showDatePicker(
54-
context: context,
55-
initialDate: _datePicked,
56-
firstDate: DateTime(2000),
57-
lastDate: DateTime(2100))
58-
.then((DateTime date) {
59-
if (date != null && date != _calendarDate)
60-
setState(() {
61-
_calendarDate = date;
62-
});
63-
});
64-
},
65-
child: Icon(
66-
Icons.date_range,
67-
color: Colors.white,
68-
),
69-
)
70-
],
71-
leading: PopupMenuButton<String>(
72-
icon: Icon(Icons.calendar_today),
73-
itemBuilder: (BuildContext context) => views.map((String choice) {
74-
return PopupMenuItem<String>(
75-
value: choice,
76-
child: Text(choice),
77-
);
78-
}).toList(),
79-
onSelected: (String value) {
80-
setState(() {
81-
if (value == 'Day') {
82-
_calendarView = CalendarView.day;
83-
} else if (value == 'Week') {
84-
_calendarView = CalendarView.week;
85-
} else if (value == 'WorkWeek') {
86-
_calendarView = CalendarView.workWeek;
87-
} else if (value == 'Month') {
88-
_calendarView = CalendarView.month;
89-
} else if (value == 'Timeline Day') {
90-
_calendarView = CalendarView.timelineDay;
91-
} else if (value == 'Timeline Week') {
92-
_calendarView = CalendarView.timelineWeek;
93-
} else if (value == 'Timeline WorkWeek') {
94-
_calendarView = CalendarView.timelineWorkWeek;
95-
}
96-
});
97-
},
27+
return MaterialApp(
28+
debugShowCheckedModeBanner: false,
29+
home: Scaffold(
30+
appBar: AppBar(
31+
actions: <Widget>[
32+
FlatButton(
33+
onPressed: () {
34+
showDatePicker(
35+
context: context,
36+
initialDate: _datePicked!,
37+
firstDate: DateTime(2000),
38+
lastDate: DateTime(2100))
39+
.then((DateTime? date) {
40+
if (date != null) _controller.displayDate = date;
41+
});
42+
},
43+
child: Icon(
44+
Icons.date_range,
45+
color: Colors.white,
46+
),
47+
)
48+
],
9849
),
99-
),
100-
body: Column(
101-
children: <Widget>[
102-
Expanded(
103-
child: SfCalendar(
104-
initialDisplayDate: _calendarDate,
105-
view: _calendarView,
106-
onViewChanged: _viewChanged,
50+
body: Column(
51+
children: <Widget>[
52+
Expanded(
53+
child: SfCalendar(
54+
view: CalendarView.week,
55+
controller: _controller,
56+
onViewChanged: _viewChanged,
57+
allowedViews: [
58+
CalendarView.day,
59+
CalendarView.week,
60+
CalendarView.workWeek,
61+
CalendarView.month,
62+
CalendarView.timelineDay,
63+
CalendarView.timelineWeek,
64+
CalendarView.timelineWorkWeek,
65+
],
66+
),
10767
),
108-
),
109-
],
68+
],
69+
),
11070
),
11171
);
11272
}
11373

11474
void _viewChanged(ViewChangedDetails viewChangedDetails) {
115-
SchedulerBinding.instance.addPostFrameCallback((duration) {
116-
_datePicked = viewChangedDetails
117-
.visibleDates[viewChangedDetails.visibleDates.length ~/ 2];
118-
});
75+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
76+
_datePicked = viewChangedDetails
77+
.visibleDates[viewChangedDetails.visibleDates.length ~/ 2];
78+
});
11979
}
12080
}

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ description: A new Flutter application.
1414
version: 1.0.0+1
1515

1616
environment:
17-
sdk: ">=2.1.0 <3.0.0"
17+
sdk: ">=2.12.0 <3.0.0"
1818

1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
syncfusion_flutter_calendar: ^17.4.39
22+
syncfusion_flutter_calendar: ^19.1.54+1
2323

2424
# The following adds the Cupertino Icons font to your application.
2525
# Use with the CupertinoIcons class for iOS style icons.
26-
cupertino_icons: ^0.1.2
26+
cupertino_icons: ^1.0.2
2727

2828
dev_dependencies:
2929
flutter_test:

0 commit comments

Comments
 (0)