Refactor codebase resolving warnings and remove self-package imports
This commit is contained in:
16
lib/view/pages/timetable/CrossPainter.dart
Normal file
16
lib/view/pages/timetable/CrossPainter.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CrossPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint()
|
||||
..color = Colors.red.withAlpha(200)
|
||||
..strokeWidth = 2.0;
|
||||
|
||||
canvas.drawLine(const Offset(0, 0), Offset(size.width, size.height), paint);
|
||||
canvas.drawLine(Offset(size.width, 0), Offset(0, size.height), paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CrossPainter oldDelegate) => false;
|
||||
}
|
130
lib/view/pages/timetable/appointmenetComponent.dart
Normal file
130
lib/view/pages/timetable/appointmenetComponent.dart
Normal file
@ -0,0 +1,130 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
import '../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
import 'CrossPainter.dart';
|
||||
|
||||
class AppointmentComponent extends StatefulWidget {
|
||||
final CalendarAppointmentDetails details;
|
||||
final bool crossedOut;
|
||||
const AppointmentComponent({Key? key, required this.details, this.crossedOut = false}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AppointmentComponent> createState() => _AppointmentComponentState();
|
||||
}
|
||||
|
||||
class _AppointmentComponentState extends State<AppointmentComponent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Appointment meeting = widget.details.appointments.first;
|
||||
final appointmentHeight = widget.details.bounds.height;
|
||||
double headerHeight = 50;
|
||||
const double footerHeight = 5;
|
||||
final double infoHeight = appointmentHeight - (headerHeight + footerHeight);
|
||||
if (infoHeight < 0) headerHeight += infoHeight;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(3),
|
||||
height: headerHeight,
|
||||
alignment: Alignment.topLeft,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.rectangle,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(5),
|
||||
topRight: Radius.circular(5),
|
||||
),
|
||||
color: meeting.color,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FittedBox(
|
||||
fit: BoxFit.fitWidth,
|
||||
child: Text(
|
||||
meeting.subject,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
),
|
||||
),
|
||||
FittedBox(
|
||||
fit: BoxFit.fitWidth,
|
||||
child: Text(
|
||||
meeting.location ?? "?",
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
softWrap: true,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: meeting.notes != null && infoHeight > 10,
|
||||
replacement: Container(
|
||||
color: meeting.color,
|
||||
height: infoHeight,
|
||||
),
|
||||
child: Container(
|
||||
height: infoHeight,
|
||||
padding: const EdgeInsets.fromLTRB(3, 5, 3, 2),
|
||||
color: meeting.color.withOpacity(0.8),
|
||||
alignment: Alignment.topLeft,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
meeting.notes ?? "",
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: footerHeight,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.rectangle,
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(5),
|
||||
bottomRight: Radius.circular(5),
|
||||
),
|
||||
color: meeting.color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Visibility(
|
||||
visible: (meeting.id as GetTimetableResponseObject).code == "cancelled",
|
||||
child: Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: CrossPainter(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
90
lib/view/pages/timetable/appointmentDetails.dart
Normal file
90
lib/view/pages/timetable/appointmentDetails.dart
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
import '../../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
|
||||
import '../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
|
||||
import '../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
import '../../../model/timetable/timetableProps.dart';
|
||||
import '../../../widget/unimplementedDialog.dart';
|
||||
import '../../settings/debug/jsonViewer.dart';
|
||||
import '../more/roomplan/roomplan.dart';
|
||||
|
||||
class AppointmentDetails {
|
||||
static String _getEventPrefix(String? code) {
|
||||
if(code == "cancelled") return "Entfällt: ";
|
||||
if(code == "irregular") return "Änderung: ";
|
||||
return code ?? "";
|
||||
}
|
||||
static void show(BuildContext context, TimetableProps webuntisData, Appointment appointment) {
|
||||
GetTimetableResponseObject timetableData = appointment.id as GetTimetableResponseObject;
|
||||
|
||||
//GetTimetableResponseObject timetableData = webuntisData.getTimetableResponse.result.firstWhere((element) => element.id == timetableObject.id);
|
||||
GetSubjectsResponseObject subject = webuntisData.getSubjectsResponse.result.firstWhere((subject) => subject.id == timetableData.su[0]['id']);
|
||||
GetRoomsResponseObject room = webuntisData.getRoomsResponse.result.firstWhere((room) => room.id == timetableData.ro[0]['id']);
|
||||
|
||||
showModalBottomSheet(context: context, builder: (context) => Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(Icons.info, color: appointment.color),
|
||||
const SizedBox(height: 10),
|
||||
Text("${_getEventPrefix(timetableData.code)}${subject.alternateName} - (${subject.longName})", style: const TextStyle(fontSize: 30)),
|
||||
Text("${Jiffy.parseFromDateTime(appointment.startTime).format(pattern: "HH:mm")} - ${Jiffy.parseFromDateTime(appointment.endTime).format(pattern: "HH:mm")}", style: const TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
title: Text("Status: ${timetableData.code != null ? "Geändert" : "Regulär"}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.room),
|
||||
title: Text("Raum: ${room.name}"),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.house_outlined),
|
||||
onPressed: () {
|
||||
PersistentNavBarNavigator.pushNewScreen(context, withNavBar: false, screen: const Roomplan());
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text("Lehrkraft: (${timetableData.te[0]['name']}) ${timetableData.te[0]['longname']}"),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.textsms_outlined),
|
||||
onPressed: () {
|
||||
UnimplementedDialog.show(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text("Typ: ${timetableData.activityType}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.people),
|
||||
title: Text("Klasse(n): ${timetableData.kl.map((e) => e['name']).join(", ")}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.bug_report_outlined),
|
||||
title: const Text("Webuntis Rohdaten zeigen"),
|
||||
onTap: () => JsonViewer.asDialog(context, timetableData.toJson()),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
58
lib/view/pages/timetable/timeRegionComponent.dart
Normal file
58
lib/view/pages/timetable/timeRegionComponent.dart
Normal file
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
class TimeRegionComponent extends StatefulWidget {
|
||||
final TimeRegionDetails details;
|
||||
const TimeRegionComponent({Key? key, required this.details}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TimeRegionComponent> createState() => _TimeRegionComponentState();
|
||||
}
|
||||
|
||||
class _TimeRegionComponentState extends State<TimeRegionComponent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String text = widget.details.region.text!;
|
||||
Color? color = widget.details.region.color;
|
||||
|
||||
if (text == 'centerIcon') {
|
||||
return Container(
|
||||
color: color,
|
||||
alignment: Alignment.center,
|
||||
child: Icon(
|
||||
widget.details.region.iconData,
|
||||
size: 17,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
);
|
||||
} else if(text.startsWith('holiday')) {
|
||||
return Container(
|
||||
color: color,
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 5),
|
||||
const Icon(Icons.cake),
|
||||
const Text("FREI"),
|
||||
const SizedBox(height: 5),
|
||||
RotatedBox(
|
||||
quarterTurns: 1,
|
||||
child: Text(
|
||||
text.split(":").last,
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
decorationStyle: TextDecorationStyle.dashed,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
230
lib/view/pages/timetable/timetable.dart
Normal file
230
lib/view/pages/timetable/timetable.dart
Normal file
@ -0,0 +1,230 @@
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
import '../../../api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
|
||||
import '../../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
|
||||
import '../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
|
||||
import '../../../model/timetable/timetableProps.dart';
|
||||
import '../../../widget/errorView.dart';
|
||||
import 'appointmenetComponent.dart';
|
||||
import 'appointmentDetails.dart';
|
||||
import 'timeRegionComponent.dart';
|
||||
import 'timetableEvents.dart';
|
||||
|
||||
class Timetable extends StatefulWidget {
|
||||
const Timetable({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Timetable> createState() => _TimetableState();
|
||||
}
|
||||
|
||||
class _TimetableState extends State<Timetable> {
|
||||
CalendarController controller = CalendarController();
|
||||
|
||||
double elementScale = 40;
|
||||
double baseElementScale = 40;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<TimetableProps>(context, listen: false).run();
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Stunden & Vertretungsplan"),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.today),
|
||||
onPressed: () {
|
||||
// controller.displayDate = DateTime.now().jumpToNextWeekDay(DateTime.monday);
|
||||
// controller.displayDate = DateTime.now().add(Duration(days: 2));
|
||||
controller.displayDate = DateTime.now();
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Consumer<TimetableProps>(
|
||||
builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return const Placeholder();
|
||||
|
||||
GetHolidaysResponse holidays = value.getHolidaysResponse;
|
||||
|
||||
if(value.hasError) {
|
||||
return ErrorView(
|
||||
icon: Icons.calendar_month,
|
||||
text: "Webuntis error: ${value.error.toString()}",
|
||||
);
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onScaleStart: (details) => baseElementScale = elementScale,
|
||||
onScaleUpdate: (details) {
|
||||
setState(() {
|
||||
elementScale = (baseElementScale * details.scale).clamp(40, 80);
|
||||
});
|
||||
},
|
||||
onScaleEnd: (details) {
|
||||
// TODO save scale for later
|
||||
},
|
||||
|
||||
child: SfCalendar(
|
||||
view: CalendarView.workWeek,
|
||||
dataSource: _buildTableEvents(value),
|
||||
|
||||
controller: controller,
|
||||
|
||||
onViewChanged: (ViewChangedDetails details) {
|
||||
log(details.visibleDates.toString());
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<TimetableProps>(context, listen: false).updateWeek(details.visibleDates.first, details.visibleDates.last);
|
||||
});
|
||||
},
|
||||
|
||||
onTap: (calendarTapDetails) {
|
||||
if(calendarTapDetails.appointments == null) return;
|
||||
Appointment tapped = calendarTapDetails.appointments!.first;
|
||||
AppointmentDetails.show(context, value, tapped);
|
||||
log(tapped.id.toString());
|
||||
},
|
||||
|
||||
firstDayOfWeek: DateTime.monday,
|
||||
specialRegions: _buildSpecialTimeRegions(holidays),
|
||||
timeSlotViewSettings: TimeSlotViewSettings(
|
||||
startHour: 07.5,
|
||||
endHour: 16.5,
|
||||
timeInterval: const Duration(minutes: 30),
|
||||
timeFormat: "HH:mm",
|
||||
dayFormat: "EE",
|
||||
timeIntervalHeight: elementScale,
|
||||
),
|
||||
|
||||
timeRegionBuilder: (BuildContext context, TimeRegionDetails timeRegionDetails) => TimeRegionComponent(details: timeRegionDetails),
|
||||
appointmentBuilder: (BuildContext context, CalendarAppointmentDetails details) => AppointmentComponent(
|
||||
details: details,
|
||||
crossedOut: value.getTimetableResponse.result.where((element) => element.id == details.appointments.first.id).firstOrNull?.code == "cancelled"
|
||||
),
|
||||
|
||||
headerHeight: 0,
|
||||
selectionDecoration: const BoxDecoration(),
|
||||
|
||||
allowAppointmentResize: false,
|
||||
allowDragAndDrop: false,
|
||||
allowViewNavigation: false,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<TimeRegion> _buildSpecialTimeRegions(GetHolidaysResponse holidays, ) {
|
||||
DateTime lastMonday = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
|
||||
DateTime firstBreak = lastMonday.copyWith(hour: 10, minute: 15);
|
||||
DateTime secondBreak = lastMonday.copyWith(hour: 13, minute: 50);
|
||||
DateTime beforeSchool = lastMonday.copyWith(hour: 7, minute: 30);
|
||||
|
||||
return [
|
||||
...holidays.result.map((e) {
|
||||
return TimeRegion(
|
||||
startTime: _parseWebuntisTimestamp(e.startDate, 755),
|
||||
endTime: _parseWebuntisTimestamp(e.startDate, 1630),
|
||||
text: 'holiday:${e.name}',
|
||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||
iconData: Icons.holiday_village_outlined
|
||||
);
|
||||
}),
|
||||
|
||||
TimeRegion(
|
||||
startTime: firstBreak,
|
||||
endTime: firstBreak.add(const Duration(minutes: 20)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
TimeRegion(
|
||||
startTime: secondBreak,
|
||||
endTime: secondBreak.add(const Duration(minutes: 15)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
TimeRegion(
|
||||
startTime: beforeSchool,
|
||||
endTime: beforeSchool.add(const Duration(minutes: 25)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||
text: "centerIcon",
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
TimetableEvents _buildTableEvents(TimetableProps data) {
|
||||
|
||||
List<Appointment> appointments = data.getTimetableResponse.result.map((element) {
|
||||
|
||||
GetRoomsResponse rooms = data.getRoomsResponse;
|
||||
GetSubjectsResponse subjects = data.getSubjectsResponse;
|
||||
|
||||
try {
|
||||
DateTime startTime = _parseWebuntisTimestamp(element.date, element.startTime);
|
||||
DateTime endTime = _parseWebuntisTimestamp(element.date, element.endTime);
|
||||
return Appointment(
|
||||
id: element,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
subject: subjects.result.firstWhere((subject) => subject.id == element.su[0]['id']).alternateName,
|
||||
location: ""
|
||||
"${rooms.result.firstWhere((room) => room.id == element.ro[0]['id']).name}"
|
||||
"\n"
|
||||
"${element.te.first['longname']}",
|
||||
notes: element.activityType,
|
||||
color: _getEventColor(element.code, startTime, endTime),
|
||||
);
|
||||
} on Error catch(e) {
|
||||
log(e.toString());
|
||||
return Appointment(
|
||||
startTime: _parseWebuntisTimestamp(element.date, element.startTime),
|
||||
endTime: _parseWebuntisTimestamp(element.date, element.endTime),
|
||||
subject: "ERROR",
|
||||
notes: element.info,
|
||||
location: 'LOCATION',
|
||||
color: Theme.of(context).primaryColor,
|
||||
startTimeZone: '',
|
||||
endTimeZone: '',
|
||||
);
|
||||
}
|
||||
}).toList();
|
||||
|
||||
return TimetableEvents(appointments);
|
||||
}
|
||||
|
||||
DateTime _parseWebuntisTimestamp(int date, int time) {
|
||||
String timeString = time.toString().padLeft(4, '0');
|
||||
return DateTime.parse('$date ${timeString.substring(0, 2)}:${timeString.substring(2, 4)}');
|
||||
}
|
||||
|
||||
Color _getEventColor(String? code, DateTime startTime, DateTime endTime) {
|
||||
int opacity = endTime.isBefore(DateTime.now()) ? 100 : 255;
|
||||
|
||||
if(code == "cancelled") return const Color(0xff000000).withAlpha(opacity);
|
||||
if(code == "irregular") return const Color(0xff8F19B3).withAlpha(opacity);
|
||||
|
||||
if(endTime.isBefore(DateTime.now())) return Theme.of(context).primaryColor.withAlpha(opacity);
|
||||
if(endTime.isAfter(DateTime.now()) && startTime.isBefore(DateTime.now())) return Theme.of(context).primaryColor.withRed(100);
|
||||
|
||||
return Theme.of(context).primaryColor;
|
||||
}
|
||||
}
|
8
lib/view/pages/timetable/timetableEvents.dart
Normal file
8
lib/view/pages/timetable/timetableEvents.dart
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
class TimetableEvents extends CalendarDataSource {
|
||||
TimetableEvents(List<Appointment> source) {
|
||||
appointments = source;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user