Loading...
Loading...
Compare original and translation side by side
| Feature | SfCalendar | SfDateRangePicker |
|---|---|---|
| Primary Purpose | Event scheduling & display | Date selection |
| Appointments/Events | ✅ Full support | ❌ Not supported |
| View Types | 9 views (day, week, timeline, etc.) | 4 views (month, year, decade, century) |
| Selection Modes | Single date/time slot | Single, multiple, range, multi-range |
| Time Slots | ✅ Yes (with time) | ❌ Dates only |
| Action Buttons | ❌ No | ✅ Confirm/Cancel buttons |
| Recurring Events | ✅ Yes | ❌ No |
| Time Zones | ✅ Yes | ❌ No |
| Resource View | ✅ Yes | ❌ No |
| Drag & Drop | ✅ Yes | ❌ No |
| 功能 | SfCalendar | SfDateRangePicker |
|---|---|---|
| 主要用途 | 事件调度与展示 | 日期选择 |
| 预约/事件 | ✅ 完全支持 | ❌ 不支持 |
| 视图类型 | 9种视图(日、周、时间轴等) | 4种视图(月、年、十年、世纪) |
| 选择模式 | 单日期/时间槽选择 | 单选、多选、范围选择、多范围选择 |
| 时间槽 | ✅ 支持(带时间) | ❌ 仅支持日期 |
| 操作按钮 | ❌ 无 | ✅ 支持确认/取消按钮 |
| 重复事件 | ✅ 支持 | ❌ 不支持 |
| 时区 | ✅ 支持 | ❌ 不支持 |
| 资源视图 | ✅ 支持 | ❌ 不支持 |
| 拖拽功能 | ✅ 支持 | ❌ 不支持 |
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
class MyCalendar extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('My Calendar')),
body: SfCalendar(
view: CalendarView.month,
dataSource: MeetingDataSource(_getDataSource()),
monthViewSettings: MonthViewSettings(
appointmentDisplayMode: MonthAppointmentDisplayMode.appointment
),
),
);
}
List<Meeting> _getDataSource() {
final List<Meeting> meetings = <Meeting>[];
final DateTime today = DateTime.now();
final DateTime startTime = DateTime(today.year, today.month, today.day, 9, 0, 0);
final DateTime endTime = startTime.add(Duration(hours: 2));
meetings.add(Meeting(
'Conference',
startTime,
endTime,
Color(0xFF0F8644),
false
));
return meetings;
}
}
class MeetingDataSource extends CalendarDataSource {
MeetingDataSource(List<Meeting> source) {
appointments = source;
}
DateTime getStartTime(int index) => appointments![index].from;
DateTime getEndTime(int index) => appointments![index].to;
String getSubject(int index) => appointments![index].eventName;
Color getColor(int index) => appointments![index].background;
bool isAllDay(int index) => appointments![index].isAllDay;
}
class Meeting {
Meeting(this.eventName, this.from, this.to, this.background, this.isAllDay);
String eventName;
DateTime from;
DateTime to;
Color background;
bool isAllDay;
}import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
class MyCalendar extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('My Calendar')),
body: SfCalendar(
view: CalendarView.month,
dataSource: MeetingDataSource(_getDataSource()),
monthViewSettings: MonthViewSettings(
appointmentDisplayMode: MonthAppointmentDisplayMode.appointment
),
),
);
}
List<Meeting> _getDataSource() {
final List<Meeting> meetings = <Meeting>[];
final DateTime today = DateTime.now();
final DateTime startTime = DateTime(today.year, today.month, today.day, 9, 0, 0);
final DateTime endTime = startTime.add(Duration(hours: 2));
meetings.add(Meeting(
'Conference',
startTime,
endTime,
Color(0xFF0F8644),
false
));
return meetings;
}
}
class MeetingDataSource extends CalendarDataSource {
MeetingDataSource(List<Meeting> source) {
appointments = source;
}
DateTime getStartTime(int index) => appointments![index].from;
DateTime getEndTime(int index) => appointments![index].to;
String getSubject(int index) => appointments![index].eventName;
Color getColor(int index) => appointments![index].background;
bool isAllDay(int index) => appointments![index].isAllDay;
}
class Meeting {
Meeting(this.eventName, this.from, this.to, this.background, this.isAllDay);
String eventName;
DateTime from;
DateTime to;
Color background;
bool isAllDay;
}import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
class MyDatePicker extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Select Date Range')),
body: SfDateRangePicker(
view: DateRangePickerView.month,
selectionMode: DateRangePickerSelectionMode.range,
onSelectionChanged: _onSelectionChanged,
showActionButtons: true,
),
);
}
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
if (args.value is PickerDateRange) {
final DateTime startDate = args.value.startDate;
final DateTime? endDate = args.value.endDate;
print('Selected range: $startDate to $endDate');
}
}
}import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
class MyDatePicker extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Select Date Range')),
body: SfDateRangePicker(
view: DateRangePickerView.month,
selectionMode: DateRangePickerSelectionMode.range,
onSelectionChanged: _onSelectionChanged,
showActionButtons: true,
),
);
}
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
if (args.value is PickerDateRange) {
final DateTime startDate = args.value.startDate;
final DateTime? endDate = args.value.endDate;
print('Selected range: $startDate to $endDate');
}
}
}SfDateRangePicker(
view: DateRangePickerView.month,
selectionMode: DateRangePickerSelectionMode.multiple,
initialSelectedDates: [
DateTime.now(),
DateTime.now().add(Duration(days: 2)),
DateTime.now().add(Duration(days: 5)),
],
onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
final List<DateTime> selectedDates = args.value;
print('Selected ${selectedDates.length} dates');
},
)SfDateRangePicker(
view: DateRangePickerView.month,
selectionMode: DateRangePickerSelectionMode.multiple,
initialSelectedDates: [
DateTime.now(),
DateTime.now().add(Duration(days: 2)),
DateTime.now().add(Duration(days: 5)),
],
onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
final List<DateTime> selectedDates = args.value;
print('Selected ${selectedDates.length} dates');
},
)// Switch between day, week, month, and schedule views
CalendarView _calendarView = CalendarView.month;
SfCalendar(
view: _calendarView,
dataSource: MeetingDataSource(_appointments),
onViewChanged: (ViewChangedDetails details) {
// Handle view changes
},
)
// Toggle view with buttons
void _changeView(CalendarView view) {
setState(() {
_calendarView = view;
});
}// 在日、周、月、日程视图之间切换
CalendarView _calendarView = CalendarView.month;
SfCalendar(
view: _calendarView,
dataSource: MeetingDataSource(_appointments),
onViewChanged: (ViewChangedDetails details) {
// 处理视图变更
},
)
// 用按钮切换视图
void _changeView(CalendarView view) {
setState(() {
_calendarView = view;
});
}// Common pattern for selecting date ranges in analytics/reports
PickerDateRange? _selectedRange;
SfDateRangePicker(
selectionMode: DateRangePickerSelectionMode.range,
onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
setState(() {
_selectedRange = args.value;
});
},
showActionButtons: true,
onSubmit: (Object? value) {
if (_selectedRange != null) {
_loadReportData(_selectedRange!.startDate, _selectedRange!.endDate);
}
Navigator.pop(context);
},
)// 分析/报表场景常用的日期范围选择模式
PickerDateRange? _selectedRange;
SfDateRangePicker(
selectionMode: DateRangePickerSelectionMode.range,
onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
setState(() {
_selectedRange = args.value;
});
},
showActionButtons: true,
onSubmit: (Object? value) {
if (_selectedRange != null) {
_loadReportData(_selectedRange!.startDate, _selectedRange!.endDate);
}
Navigator.pop(context);
},
)// Custom styling for both components
SfCalendar(
view: CalendarView.month,
todayHighlightColor: Colors.blue,
cellBorderColor: Colors.grey[300],
backgroundColor: Colors.white,
selectionDecoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(color: Colors.blue, width: 2),
borderRadius: BorderRadius.circular(4),
),
)
SfDateRangePicker(
todayHighlightColor: Colors.green,
selectionColor: Colors.blue,
rangeSelectionColor: Colors.blue.withOpacity(0.3),
startRangeSelectionColor: Colors.blue,
endRangeSelectionColor: Colors.blue,
)// 两个组件通用的自定义样式
SfCalendar(
view: CalendarView.month,
todayHighlightColor: Colors.blue,
cellBorderColor: Colors.grey[300],
backgroundColor: Colors.white,
selectionDecoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(color: Colors.blue, width: 2),
borderRadius: BorderRadius.circular(4),
),
)
SfDateRangePicker(
todayHighlightColor: Colors.green,
selectionColor: Colors.blue,
rangeSelectionColor: Colors.blue.withOpacity(0.3),
startRangeSelectionColor: Colors.blue,
endRangeSelectionColor: Colors.blue,
)// Disable past dates and weekends
SfDateRangePicker(
minDate: DateTime.now(),
maxDate: DateTime.now().add(Duration(days: 365)),
selectableDayPredicate: (DateTime date) {
// Disable weekends
return date.weekday != DateTime.saturday &&
date.weekday != DateTime.sunday;
},
)// 禁用过去日期和周末
SfDateRangePicker(
minDate: DateTime.now(),
maxDate: DateTime.now().add(Duration(days: 365)),
selectableDayPredicate: (DateTime date) {
// 禁用周末
return date.weekday != DateTime.saturday &&
date.weekday != DateTime.sunday;
},
)viewdataSourceinitialDisplayDateinitialSelectedDatemonthViewSettingstimeSlotViewSettingsscheduleViewSettingstodayHighlightColorselectionDecorationonTaponLongPressonViewChangedonSelectionChangedshowNavigationArrowshowCurrentTimeIndicatorallowViewNavigationfirstDayOfWeekblackoutDatesminDatemaxDateviewdataSourceinitialDisplayDateinitialSelectedDatemonthViewSettingstimeSlotViewSettingsscheduleViewSettingstodayHighlightColorselectionDecorationonTaponLongPressonViewChangedonSelectionChangedshowNavigationArrowshowCurrentTimeIndicatorallowViewNavigationfirstDayOfWeekblackoutDatesminDatemaxDateviewselectionModeinitialSelectedDateinitialSelectedDatesinitialSelectedRangeinitialSelectedRangesinitialDisplayDatemonthViewSettingsyearViewSettingstodayHighlightColorselectionColorrangeSelectionColorstartRangeSelectionColorendRangeSelectionColoronSelectionChangedonViewChangedonSubmitonCancelshowActionButtonsshowTodayButtonallowViewNavigationenablePastDatesminDatemaxDateselectableDayPredicatemonthCellStyleyearCellStyleviewselectionModeinitialSelectedDateinitialSelectedDatesinitialSelectedRangeinitialSelectedRangesinitialDisplayDatemonthViewSettingsyearViewSettingstodayHighlightColorselectionColorrangeSelectionColorstartRangeSelectionColorendRangeSelectionColoronSelectionChangedonViewChangedonSubmitonCancelshowActionButtonsshowTodayButtonallowViewNavigationenablePastDatesminDatemaxDateselectableDayPredicatemonthCellStyleyearCellStyle