-
-
Save ConcenTech/7d657372fff9e9e0afbf9e82cdfb2cdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:syncfusion_flutter_calendar/calendar.dart'; | |
| void main() { | |
| runApp(ProviderScope(child: MyApp())); | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold( | |
| body: MyCalendar(), | |
| )); | |
| } | |
| } | |
| class MyCalendar extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return SfCalendar( | |
| allowViewNavigation: false, | |
| view: CalendarView.month, | |
| dataSource: TimeTableDataSource(SAMPLE_DATA), | |
| firstDayOfWeek: 1, | |
| monthViewSettings: MonthViewSettings( | |
| appointmentDisplayMode: MonthAppointmentDisplayMode.appointment, | |
| ), | |
| ); | |
| } | |
| } | |
| final SAMPLE_DATA = [ | |
| CalendarEntry( | |
| eventName: 'Event one', | |
| from: DateTime(2021, 04, 12), | |
| to: DateTime(2021, 04, 18), | |
| background: Colors.blue, | |
| isAllDay: true, | |
| ), | |
| CalendarEntry( | |
| eventName: 'Event two', | |
| from: DateTime(2021, 04, 19), | |
| to: DateTime(2021, 04, 21), | |
| background: Colors.green, | |
| isAllDay: true, | |
| ), | |
| CalendarEntry( | |
| eventName: 'Event three', | |
| from: DateTime.now(), | |
| to: DateTime.now(), | |
| background: Colors.red, | |
| isAllDay: true, | |
| ), | |
| ]; | |
| class TimeTableDataSource extends CalendarDataSource { | |
| TimeTableDataSource(List<CalendarEntry> source) { | |
| appointments = source; | |
| } | |
| @override | |
| DateTime getStartTime(int index) { | |
| return appointments[index].from; | |
| } | |
| @override | |
| DateTime getEndTime(int index) { | |
| return appointments[index].to; | |
| } | |
| @override | |
| String getSubject(int index) { | |
| return appointments[index].eventName; | |
| } | |
| @override | |
| Color getColor(int index) { | |
| return appointments[index].background; | |
| } | |
| @override | |
| bool isAllDay(int index) { | |
| return appointments[index].isAllDay; | |
| } | |
| } | |
| class CalendarEntry { | |
| final String eventName; | |
| final DateTime from; | |
| final DateTime to; | |
| final Color background; | |
| final bool isAllDay; | |
| CalendarEntry({ | |
| @required this.eventName, | |
| @required this.from, | |
| @required this.to, | |
| @required this.background, | |
| @required this.isAllDay, | |
| }); | |
| CalendarEntry.empty() | |
| : this.eventName = '', | |
| this.from = null, | |
| this.to = null, | |
| this.background = null, | |
| this.isAllDay = true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment