feat:增加日程模块tab页面

This commit is contained in:
2025-11-13 16:11:19 +08:00
parent 54bed08b7b
commit 427e9f0a48
4 changed files with 66 additions and 33 deletions

View File

@@ -74,6 +74,7 @@ class MyApp extends StatelessWidget {
locale: Locale('zh', 'CN'),
theme: appProvider.currentThemeData,
home: const MainScreen(),
debugShowCheckedModeBanner: false,
);
},
),

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
// flutter packages pub run build_runner build
part 'calendar.g.dart';
@@ -52,3 +53,14 @@ class Calendar extends HiveObject {
);
}
}
enum CalendarTab {
week('周视图', CalendarView.week),
month('月视图', CalendarView.month),
schedule('日程视图', CalendarView.schedule);
final String label;
final CalendarView view;
const CalendarTab(this.label, this.view);
}

View File

@@ -23,6 +23,7 @@ class CalendarPageState extends State<CalendarPage> {
final CalendarService calendarService = CalendarService();
final NotifyService notifyService = NotifyService();
late List<Appointment> _appointments;
CalendarTab _currentTab = CalendarTab.week;
void showAddDialog() {
_showDialog(false, null);
@@ -131,45 +132,46 @@ class CalendarPageState extends State<CalendarPage> {
Widget build(BuildContext context) {
final provider = Provider.of<CalendarProvider>(context, listen: false);
return Scaffold(
appBar: AppBar(
title: Text('日程安排'),
centerTitle: true,
actions: [
buildCalendarMenu(
onSelected: (CalendarView value) {
return Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
buildTabs(
context: context,
currentTab: _currentTab,
onTabChanged: (value) {
setState(() {
_calendarController.view = value;
_currentTab = value;
_calendarController.view = value.view;
});
},
),
Expanded(
child: buildCalendar(
context: context,
controller: _calendarController,
dataSource: AppointmentDataSource(_appointments),
onAdd: () {
if (_calendarController.view == CalendarView.week) {
_showDialog(true, provider.formItem);
}
},
onEdit: (appointment) {
final calendar = calendarService.getCalendarById(
appointment.id as int,
);
_showDialog(true, calendar);
},
onDelete: (appointment) {
final calendar = calendarService.getCalendarById(
appointment.id as int,
);
_deleteCalendar(calendar);
},
),
),
],
),
body: Padding(
padding: EdgeInsets.all(10),
child: buildCalendar(
context: context,
controller: _calendarController,
dataSource: AppointmentDataSource(_appointments),
onAdd: () {
if (_calendarController.view == CalendarView.week) {
_showDialog(true, provider.formItem);
}
},
onEdit: (appointment) {
final calendar = calendarService.getCalendarById(
appointment.id as int,
);
_showDialog(true, calendar);
},
onDelete: (appointment) {
final calendar = calendarService.getCalendarById(
appointment.id as int,
);
_deleteCalendar(calendar);
},
),
),
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:flisp_app/models/calendar.dart';
import 'package:flisp_app/provider/calendar_provider.dart';
import 'package:flisp_app/widgets/common.dart';
import 'package:flutter/material.dart';
@@ -16,6 +17,23 @@ class AppointmentDataSource extends CalendarDataSource {
}
}
Widget buildTabs({
required BuildContext context,
required CalendarTab currentTab,
required ValueChanged<CalendarTab> onTabChanged,
}) {
return Container(
padding: EdgeInsets.all(8),
child: buildToggleSwitch(
context: context,
currentTab: currentTab,
tabValues: CalendarTab.values,
labels: CalendarTab.values.map((e) => e.label).toList(),
onTabChanged: onTabChanged,
),
);
}
Widget buildCalendarMenu({required void Function(CalendarView) onSelected}) {
return PopupMenuButton<CalendarView>(
onSelected: onSelected,