create MIHCalendar widget

This commit is contained in:
2024-11-07 11:44:22 +02:00
parent fd6c1ea9c5
commit 8d003c0bef

View File

@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/main.dart';
import 'package:table_calendar/table_calendar.dart';
class MIHCalendar extends StatefulWidget {
final double calendarWidth;
final double rowHeight;
const MIHCalendar({
super.key,
required this.calendarWidth,
required this.rowHeight,
});
@override
State<MIHCalendar> createState() => _MIHCalendarState();
}
class _MIHCalendarState extends State<MIHCalendar> {
DateTime selectedDay = DateTime.now();
CalendarFormat _calendarFormat = CalendarFormat.week;
void onDaySelected(DateTime day, DateTime focusedDay) {
setState(() {
selectedDay = day;
});
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: widget.calendarWidth,
child: TableCalendar(
headerStyle: HeaderStyle(
formatButtonDecoration: BoxDecoration(
border: Border.fromBorderSide(
BorderSide(
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
),
),
borderRadius: const BorderRadius.all(
Radius.circular(12.0),
),
),
// formatButtonTextStyle:
),
rowHeight: widget.rowHeight,
focusedDay: selectedDay,
firstDay: DateTime.utc(2024, 1, 1),
lastDay: DateTime.utc(2099, 1, 1),
onDaySelected: onDaySelected,
selectedDayPredicate: (day) => isSameDay(day, selectedDay),
calendarFormat: _calendarFormat,
onFormatChanged: (format) {
setState(() {
_calendarFormat = format;
});
},
calendarStyle: CalendarStyle(
outsideDaysVisible: false,
todayTextStyle: TextStyle(
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
),
todayDecoration: BoxDecoration(
color: MzanziInnovationHub.of(context)!.theme.messageTextColor(),
shape: BoxShape.circle,
),
selectedTextStyle: TextStyle(
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
),
selectedDecoration: BoxDecoration(
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
shape: BoxShape.circle,
),
weekendTextStyle: TextStyle(
color: MzanziInnovationHub.of(context)!.theme.messageTextColor(),
),
),
daysOfWeekStyle: DaysOfWeekStyle(
weekdayStyle: TextStyle(
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
),
weekendStyle: TextStyle(
color: MzanziInnovationHub.of(context)!.theme.messageTextColor(),
),
),
),
);
}
}