Files
eatvio_app/lib/features/diets/presentation/widgets/calendar_widget.dart
2024-11-26 19:51:08 +07:00

111 lines
3.6 KiB
Dart

import 'package:eatvio_app/core/utils/string_extentions.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:table_calendar/table_calendar.dart';
class CalendarWidget extends StatefulWidget {
const CalendarWidget({super.key});
@override
State<CalendarWidget> createState() => _CalendarWidgetState();
}
class _CalendarWidgetState extends State<CalendarWidget> {
CalendarFormat _calendarFormat = CalendarFormat.week;
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay = DateTime.now();
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(top: 5),
child: TableCalendar(
firstDay: DateTime.now(),
lastDay: DateTime.utc(2030, 3, 14),
locale: 'ru_RU',
startingDayOfWeek: StartingDayOfWeek.monday,
focusedDay: _focusedDay,
calendarFormat: _calendarFormat,
calendarBuilders: CalendarBuilders(
headerTitleBuilder: (context, day) {
final dateFormatter = DateFormat('MMMM', 'ru_RU');
return Center(
child: Text(
'${dateFormatter.format(day).capitalize()}',
style: TextStyle(color: appTheme.black, fontSize: 16, fontWeight: FontWeight.w400),
),
);
},
),
headerStyle: HeaderStyle(
titleCentered: true,
formatButtonVisible: false,
leftChevronVisible: false,
rightChevronVisible: false,
),
rowHeight: 64,
selectedDayPredicate: (day) {
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
if (!isSameDay(_selectedDay, selectedDay)) {
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
}
},
onFormatChanged: (format) {
if (_calendarFormat != format) {
setState(() {
_calendarFormat = format;
});
}
},
onPageChanged: (focusedDay) {
_focusedDay = focusedDay;
},
calendarStyle: CalendarStyle(
weekendTextStyle: TextStyle(
color: appTheme.gray,
),
defaultTextStyle: TextStyle(
color: appTheme.gray,
),
weekendDecoration: BoxDecoration(
color: appTheme.dividerColor,
shape: BoxShape.circle,
),
defaultDecoration: BoxDecoration(
color: appTheme.dividerColor,
shape: BoxShape.circle,
),
selectedTextStyle: TextStyle(
color: appTheme.whiteA700,
),
selectedDecoration: BoxDecoration(
color: appTheme.blueA400,
shape: BoxShape.circle,
),
todayTextStyle: TextStyle(
color: appTheme.gray,
),
todayDecoration: BoxDecoration(
border: Border.all(
color: appTheme.blueA400,
width: 2,
),
color: appTheme.dividerColor,
shape: BoxShape.circle,
),
),
),
),
],
);
}
}