forked from eatvio/eatvio_app
91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:eatvio_app/theme/theme_helper.dart';
|
|
import 'package:flutter/material.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.month;
|
|
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.utc(2010, 10, 16),
|
|
lastDay: DateTime.utc(2030, 3, 14),
|
|
locale: 'ru_RU',
|
|
startingDayOfWeek: StartingDayOfWeek.monday,
|
|
focusedDay: _focusedDay,
|
|
rangeStartDay: _selectedDay,
|
|
rangeEndDay: _selectedDay?.add(const Duration(days: 6)),
|
|
calendarFormat: _calendarFormat,
|
|
headerStyle: HeaderStyle(
|
|
titleCentered: true,
|
|
formatButtonVisible: false,
|
|
leftChevronVisible: false,
|
|
rightChevronVisible: false,
|
|
),
|
|
rowHeight: 40,
|
|
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(
|
|
weekendDecoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
),
|
|
defaultDecoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
),
|
|
selectedDecoration: BoxDecoration(
|
|
color: appTheme.blueA400,
|
|
shape: BoxShape.circle,
|
|
),
|
|
todayTextStyle: TextStyle(
|
|
color: Colors.black,
|
|
),
|
|
todayDecoration: BoxDecoration(
|
|
border: Border.all(
|
|
color: appTheme.blueA400,
|
|
width: 2,
|
|
),
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|