@@ -21,77 +21,64 @@ class PickerCurrentMonth extends StatefulWidget {
2121 _PickerCurrentMonthState createState () => _PickerCurrentMonthState ();
2222}
2323
24- List <String > views = < String > ['Month' , 'Year' , 'Decade' , 'Century' ];
25-
2624class _PickerCurrentMonthState extends State <PickerCurrentMonth > {
27- DateRangePickerController _controller;
28- String _startDate, _endDate;
29-
30- @override
31- void initState () {
32- // TODO: implement initState
33- _controller = DateRangePickerController ();
34- _startDate = '' ;
35- _endDate = '' ;
36- super .initState ();
37- }
25+ final DateRangePickerController _controller = DateRangePickerController ();
26+ final List <String > views = < String > ['Month' , 'Year' , 'Decade' , 'Century' ];
27+ String _startDate = '' , _endDate = '' ;
3828
3929 @override
4030 Widget build (BuildContext context) {
4131 return Scaffold (
42- appBar: AppBar (
43- leading: PopupMenuButton <String >(
44- icon: Icon (Icons .calendar_today),
45- itemBuilder: (BuildContext context) => views.map ((String choice) {
46- return PopupMenuItem <String >(
47- value: choice,
48- child: Text (choice),
49- );
50- }).toList (),
51- onSelected: (String value) {
52- if (value == 'Month' ) {
53- _controller.view = DateRangePickerView .month;
54- } else if (value == 'Year' ) {
55- _controller.view = DateRangePickerView .year;
56- } else if (value == 'Decade' ) {
57- _controller.view = DateRangePickerView .decade;
58- } else if (value == 'Century' ) {
59- _controller.view = DateRangePickerView .century;
60- }
61- },
62- ),
63- ),
64- body: Column (
65- children: < Widget > [
66- Container ( height: 50 ,
67- child: Text ('StartDate:''$_startDate ' )),
68- Container (height: 50
69- ,child: Text ('EndDate:''$_endDate ' )),
70- Card (
71- margin: const EdgeInsets .fromLTRB (40 , 100 , 50 , 40 ),
72- child: SfDateRangePicker (
73- controller: _controller,
74- view: DateRangePickerView .month,
75- onViewChanged: viewChanged,
76- ),
77- )
78- ],
32+ appBar: AppBar (
33+ leading: PopupMenuButton <String >(
34+ icon: Icon (Icons .calendar_today),
35+ itemBuilder: (BuildContext context) => views.map ((String choice) {
36+ return PopupMenuItem <String >(
37+ value: choice,
38+ child: Text (choice),
39+ );
40+ }).toList (),
41+ onSelected: (String value) {
42+ if (value == 'Month' ) {
43+ _controller.view = DateRangePickerView .month;
44+ } else if (value == 'Year' ) {
45+ _controller.view = DateRangePickerView .year;
46+ } else if (value == 'Decade' ) {
47+ _controller.view = DateRangePickerView .decade;
48+ } else if (value == 'Century' ) {
49+ _controller.view = DateRangePickerView .century;
50+ }
51+ },
7952 ),
53+ ),
54+ body: Column (
55+ children: < Widget > [
56+ Container (height: 50 , child: Text ('StartDate:' '$_startDate ' )),
57+ Container (height: 50 , child: Text ('EndDate:' '$_endDate ' )),
58+ Card (
59+ margin: const EdgeInsets .fromLTRB (40 , 100 , 50 , 40 ),
60+ child: SfDateRangePicker (
61+ controller: _controller,
62+ view: DateRangePickerView .month,
63+ onViewChanged: viewChanged,
64+ ),
65+ )
66+ ],
67+ ),
8068
81- // This trailing comma makes auto-formatting nicer for build methods.
82- );
69+ // This trailing comma makes auto-formatting nicer for build methods.
70+ );
8371 }
8472
8573 void viewChanged (DateRangePickerViewChangedArgs args) {
86-
87- _startDate = DateFormat ('dd, MMMM yyyy' )
88- .format (args.visibleDateRange.startDate)
89- .toString ();
90- _endDate= DateFormat ('dd, MMMM yyyy' )
91- .format (args.visibleDateRange.endDate)
92- .toString ();
93- SchedulerBinding .instance.addPostFrameCallback ((duration) {
94- setState (() {});
95- });
74+ _startDate = DateFormat ('dd, MMMM yyyy' )
75+ .format (args.visibleDateRange.startDate! )
76+ .toString ();
77+ _endDate = DateFormat ('dd, MMMM yyyy' )
78+ .format (args.visibleDateRange.endDate! )
79+ .toString ();
80+ SchedulerBinding .instance! .addPostFrameCallback ((duration) {
81+ setState (() {});
82+ });
9683 }
9784}
0 commit comments