feat:增加日程模块tab页面
This commit is contained in:
@@ -74,6 +74,7 @@ class MyApp extends StatelessWidget {
|
|||||||
locale: Locale('zh', 'CN'),
|
locale: Locale('zh', 'CN'),
|
||||||
theme: appProvider.currentThemeData,
|
theme: appProvider.currentThemeData,
|
||||||
home: const MainScreen(),
|
home: const MainScreen(),
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||||
|
|
||||||
// flutter packages pub run build_runner build
|
// flutter packages pub run build_runner build
|
||||||
part 'calendar.g.dart';
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class CalendarPageState extends State<CalendarPage> {
|
|||||||
final CalendarService calendarService = CalendarService();
|
final CalendarService calendarService = CalendarService();
|
||||||
final NotifyService notifyService = NotifyService();
|
final NotifyService notifyService = NotifyService();
|
||||||
late List<Appointment> _appointments;
|
late List<Appointment> _appointments;
|
||||||
|
CalendarTab _currentTab = CalendarTab.week;
|
||||||
|
|
||||||
void showAddDialog() {
|
void showAddDialog() {
|
||||||
_showDialog(false, null);
|
_showDialog(false, null);
|
||||||
@@ -131,45 +132,46 @@ class CalendarPageState extends State<CalendarPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final provider = Provider.of<CalendarProvider>(context, listen: false);
|
final provider = Provider.of<CalendarProvider>(context, listen: false);
|
||||||
|
|
||||||
return Scaffold(
|
return Padding(
|
||||||
appBar: AppBar(
|
padding: EdgeInsets.all(10),
|
||||||
title: Text('日程安排'),
|
child: Column(
|
||||||
centerTitle: true,
|
children: [
|
||||||
actions: [
|
buildTabs(
|
||||||
buildCalendarMenu(
|
context: context,
|
||||||
onSelected: (CalendarView value) {
|
currentTab: _currentTab,
|
||||||
|
onTabChanged: (value) {
|
||||||
setState(() {
|
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);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flisp_app/models/calendar.dart';
|
||||||
import 'package:flisp_app/provider/calendar_provider.dart';
|
import 'package:flisp_app/provider/calendar_provider.dart';
|
||||||
import 'package:flisp_app/widgets/common.dart';
|
import 'package:flisp_app/widgets/common.dart';
|
||||||
import 'package:flutter/material.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}) {
|
Widget buildCalendarMenu({required void Function(CalendarView) onSelected}) {
|
||||||
return PopupMenuButton<CalendarView>(
|
return PopupMenuButton<CalendarView>(
|
||||||
onSelected: onSelected,
|
onSelected: onSelected,
|
||||||
|
|||||||
Reference in New Issue
Block a user