import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:intl/date_symbol_data_local.dart';
void main() {
// Initialisez les données de date locales
initializeDateFormatting().then((_) => runApp(MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Calendar Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: CalendarPage(),
);
}
}
class CalendarPage extends StatefulWidget {
@override
_CalendarPageState createState() => _CalendarPageState();
}
class _CalendarPageState extends State {
CalendarFormat _calendarFormat = CalendarFormat.month;
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Table Calendar Example'),
),
body: TableCalendar(
locale: 'fr_FR', // Changez la langue en français
firstDay: DateTime.utc(2020, 1, 1),
lastDay: DateTime.utc(2030, 12, 31),
focusedDay: _focusedDay,
calendarFormat: _calendarFormat,
startingDayOfWeek: StartingDayOfWeek.monday, // Début de la semaine fixé à lundi
selectedDayPredicate: (day) {
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
},
onFormatChanged: (format) {
if (_calendarFormat != format) {
setState(() {
_calendarFormat = format;
});
}
},
onPageChanged: (focusedDay) {
_focusedDay = focusedDay;
},
calendarStyle: CalendarStyle(
todayDecoration: BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
selectedDecoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
weekendTextStyle: TextStyle(color: Colors.red),
holidayTextStyle: TextStyle(color: Colors.purple),
),
daysOfWeekStyle: DaysOfWeekStyle(
weekdayStyle: TextStyle(color: Colors.blue),
weekendStyle: TextStyle(color: Colors.red),
),
headerStyle: HeaderStyle(
formatButtonVisible: false,
titleCentered: true,
leftChevronIcon: Icon(Icons.chevron_left, color: Colors.blue),
rightChevronIcon: Icon(Icons.chevron_right, color: Colors.blue),
),
),
);
}
}