feat:增加日程模块
This commit is contained in:
89
lib/widgets/calendar_widget.dart
Normal file
89
lib/widgets/calendar_widget.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flisp_app/provider/calendar_provider.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
final viewItems = [
|
||||
{'value': CalendarView.week, 'label': '周视图'},
|
||||
{'value': CalendarView.month, 'label': '月视图'},
|
||||
{'value': CalendarView.schedule, 'label': '日程视图'},
|
||||
];
|
||||
|
||||
class AppointmentDataSource extends CalendarDataSource {
|
||||
AppointmentDataSource(List<Appointment> source) {
|
||||
appointments = source;
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildCalendarMenu({required void Function(CalendarView) onSelected}) {
|
||||
return PopupMenuButton<CalendarView>(
|
||||
onSelected: onSelected,
|
||||
itemBuilder: (BuildContext context) {
|
||||
return viewItems.map((item) {
|
||||
return PopupMenuItem<CalendarView>(
|
||||
value: item['value'] as CalendarView,
|
||||
child: Text(item['label'].toString()),
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildCalendar({
|
||||
required BuildContext context,
|
||||
required CalendarController controller,
|
||||
required CalendarDataSource dataSource,
|
||||
required VoidCallback onAdd,
|
||||
required ValueChanged<Appointment> onEdit,
|
||||
required ValueChanged<Appointment> onDelete,
|
||||
}) {
|
||||
final provider = Provider.of<CalendarProvider>(context);
|
||||
|
||||
return SfCalendar(
|
||||
view: CalendarView.week,
|
||||
controller: controller,
|
||||
dataSource: dataSource,
|
||||
firstDayOfWeek: 1,
|
||||
showDatePickerButton: true,
|
||||
showNavigationArrow: true,
|
||||
allowViewNavigation: true,
|
||||
// 月份视图设置
|
||||
monthViewSettings: MonthViewSettings(
|
||||
appointmentDisplayMode: MonthAppointmentDisplayMode.appointment,
|
||||
showAgenda: true,
|
||||
),
|
||||
// 时间区域设置
|
||||
timeSlotViewSettings: TimeSlotViewSettings(
|
||||
startHour: 7,
|
||||
endHour: 23,
|
||||
timeFormat: 'HH:mm',
|
||||
timeInterval: Duration(minutes: 30),
|
||||
timeRulerSize: 60,
|
||||
),
|
||||
// 选择日期回调
|
||||
onTap: (CalendarTapDetails details) {
|
||||
if (details.targetElement == CalendarElement.calendarCell) {
|
||||
if (!details.date!.isBefore(DateTime.now())) {
|
||||
provider.initFormByDate(details.date!);
|
||||
onAdd();
|
||||
}
|
||||
} else if (details.targetElement == CalendarElement.appointment) {
|
||||
if (details.appointments?.length == 1) {
|
||||
onEdit(details.appointments!.first);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 选择日程回调
|
||||
onLongPress: (CalendarLongPressDetails details) async {
|
||||
if (details.targetElement == CalendarElement.appointment) {
|
||||
if (details.appointments?.length == 1) {
|
||||
final bool? result = await showDeleteConfirmationDialog(context);
|
||||
if (result == true) {
|
||||
onDelete(details.appointments!.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user